pub struct StructsyQueryTx<'a, T: Persistent + 'static> { /* private fields */ }
Expand description

Query for a persistent struct considering in transaction changes.

Example

use structsy::{ Structsy, StructsyTx, StructsyError};
use structsy_derive::{queries, Persistent};
#[derive(Persistent)]
struct Basic {
    name: String,
}
impl Basic {
    fn new(name: &str) -> Basic {
        Basic { name: name.to_string() }
    }
}

#[queries(Basic)]
trait BasicQuery {
    fn by_name(self, name: String) -> Self;
}


fn basic_query() -> Result<(), StructsyError> {
    let structsy = Structsy::open("file.structsy")?;
    structsy.define::<Basic>()?;
    let mut tx = structsy.begin()?;
    tx.insert(&Basic::new("aaa"))?;
    let count = tx.query::<Basic>().by_name("aaa".to_string()).fetch().count();
    assert_eq!(count, 1);
    tx.commit()?;
    Ok(())
}

Implementations§

source§

impl<'a, T: Persistent> StructsyQueryTx<'a, T>

source

pub fn projection<P: Projection<T>>(self) -> ProjectionQueryTx<'a, P, T>

Make a projection from filtered structs.

Example
use structsy::{ Structsy, StructsyTx, StructsyError, Filter};
use structsy_derive::{queries, Projection, Persistent};

#[derive(Persistent)]
struct Person {
    name:String,
    surname:String,
}

impl Person {
    fn new(name:&str, surname:&str) -> Self {
        Person {
            name: name.to_string(),
            surname: surname.to_string(),
        }
    }
}

#[queries(Person)]
trait PersonQuery {
    fn by_name(self, name:&str) -> Self;
}

#[derive(Projection)]
#[projection = "Person" ]
struct NameProjection {
    name:String,
}


fn main() -> Result<(), StructsyError> {
    let structsy = Structsy::memory()?;
    structsy.define::<Person>()?;
    let mut tx = structsy.begin()?;
    tx.insert(&Person::new("a_name", "a_surname"))?;
    tx.commit()?;
    let query = structsy.query::<Person>().by_name("a_name").projection::<NameProjection>();
    assert_eq!(query.fetch().next().unwrap().name, "a_name");
    Ok(())
}
source

pub fn fetch(self) -> StructsyIter<'a, (Ref<T>, T)>

Trait Implementations§

source§

impl<'a, T: Persistent> IntoIterator for StructsyQueryTx<'a, T>

§

type Item = (Ref<T>, T)

The type of the elements being iterated over.
§

type IntoIter = StructsyIter<'a, (Ref<T>, T)>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, T: Persistent + 'static> Query<T> for StructsyQueryTx<'a, T>

source§

fn filter_builder(&mut self) -> &mut FilterBuilder<T>

source§

fn add_group(&mut self, filter: Filter<T>)

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for StructsyQueryTx<'a, T>

§

impl<'a, T> !Send for StructsyQueryTx<'a, T>

§

impl<'a, T> !Sync for StructsyQueryTx<'a, T>

§

impl<'a, T> Unpin for StructsyQueryTx<'a, T>

§

impl<'a, T> !UnwindSafe for StructsyQueryTx<'a, T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V