|
@@ -5,7 +5,8 @@ use crate::model::Modelable;
|
|
|
|
|
|
// pub mod expr;
|
|
|
// pub mod condition;
|
|
|
-pub mod builder;
|
|
|
+// pub mod builder;
|
|
|
+pub mod build;
|
|
|
|
|
|
/// Wraps an entity with its ID, for example as a query result.
|
|
|
///
|
|
@@ -425,35 +426,44 @@ impl<'l> QueryInterface<'l> {
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
-
|
|
|
qi.get().by(Table::Column, value).by(Table::OtherColumn, value).one()
|
|
|
qi.get().id(some_id).one()
|
|
|
qi.get().by(Table::Column, value).all()
|
|
|
+*/
|
|
|
|
|
|
- * */
|
|
|
|
|
|
+/*
|
|
|
pub struct BuildResult(String, bool);
|
|
|
|
|
|
pub trait Buildable {
|
|
|
fn build() -> BuildResult;
|
|
|
}
|
|
|
|
|
|
-pub trait Gettable<'sq, 'l, T: Entity> {
|
|
|
+pub trait Gettable<'sq, 'l, T: Entity>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
type Builder: Buildable;
|
|
|
- fn qi(&self) -> &'sq QueryInterface<'l> { todo!() }
|
|
|
+ fn qi(&self) -> &'sq QueryInterface<'l> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-pub struct GetQuery<'sq, 'l, T: Entity> {
|
|
|
+pub struct GetQuery<'sq, 'l, T: Entity>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
qi: &'sq QueryInterface<'l>,
|
|
|
_ghost: std::marker::PhantomData<(T, &'sq str)>,
|
|
|
}
|
|
|
|
|
|
-
|
|
|
impl<'sq, 'l, T: Entity> Gettable<'sq, 'l, T> for GetQuery<'sq, 'l, T> {
|
|
|
type Builder = GetBuild<T>;
|
|
|
}
|
|
|
|
|
|
-pub struct GetBuild<T: Entity> { _ghost: std::marker::PhantomData<T> }
|
|
|
+pub struct GetBuild<T: Entity> {
|
|
|
+ _ghost: std::marker::PhantomData<T>,
|
|
|
+}
|
|
|
|
|
|
impl<T: Entity> Buildable for GetBuild<T> {
|
|
|
fn build() -> BuildResult {
|
|
@@ -461,7 +471,10 @@ impl<T: Entity> Buildable for GetBuild<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub struct ByClause<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>> {
|
|
|
+pub struct ByClause<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
wrap: Wrap,
|
|
|
col: &'sq Col,
|
|
|
data: &'sq dyn Modelable,
|
|
@@ -469,7 +482,7 @@ pub struct ByClause<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Get
|
|
|
}
|
|
|
|
|
|
pub struct ByBuild<Col: EntityColumn, Wrap: Buildable> {
|
|
|
- _ghost: std::marker::PhantomData<(Col, Wrap)>
|
|
|
+ _ghost: std::marker::PhantomData<(Col, Wrap)>,
|
|
|
}
|
|
|
|
|
|
impl<Col: EntityColumn, Wrap: Buildable> Buildable for ByBuild<Col, Wrap> {
|
|
@@ -479,25 +492,38 @@ impl<Col: EntityColumn, Wrap: Buildable> Buildable for ByBuild<Col, Wrap> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<'sq, 'l, T: Entity> GetQuery<'sq, 'l, T> {
|
|
|
- pub fn by<NCol: EntityColumn<Entity = T>>(self, col: &'sq NCol, data: &'sq dyn Modelable) -> ByClause<'sq, 'l, T, NCol, Self> {
|
|
|
- ByClause { wrap: self, col, data, _ghost: std::marker::PhantomData }
|
|
|
+impl<'sq, 'l, T: Entity> GetQuery<'sq, 'l, T>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
+ pub fn by<NCol: EntityColumn<Entity = T>>(
|
|
|
+ self,
|
|
|
+ col: &'sq NCol,
|
|
|
+ data: &'sq dyn Modelable,
|
|
|
+ ) -> ByClause<'sq, 'l, T, NCol, Self> {
|
|
|
+ ByClause {
|
|
|
+ wrap: self,
|
|
|
+ col,
|
|
|
+ data,
|
|
|
+ _ghost: std::marker::PhantomData,
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>> Gettable<'sq, 'l, T> for ByClause<'sq, 'l, T, Col, Wrap> {
|
|
|
+impl<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>>
|
|
|
+ Gettable<'sq, 'l, T> for ByClause<'sq, 'l, T, Col, Wrap>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
type Builder = ByBuild<Col, Wrap::Builder>;
|
|
|
-
|
|
|
- /*fn build_query(&self) -> (String, bool) {
|
|
|
- let (parent, is_where) = self.wrap.build_query();
|
|
|
- (format!("{} {} {} = ?", parent, if is_where { "AND" } else { "WHERE" }, "<>"), true)
|
|
|
- }*/
|
|
|
}
|
|
|
|
|
|
-impl<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>> ByClause<'sq, 'l, T, Col, Wrap> {
|
|
|
+impl<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l, T>>
|
|
|
+ ByClause<'sq, 'l, T, Col, Wrap>
|
|
|
+where
|
|
|
+ 'l: 'sq,
|
|
|
+{
|
|
|
fn build_query(&self) {
|
|
|
- // <Self as Gettable<T>>::build_query(self);
|
|
|
- // <Self as Gettable<T>>::Builder;
|
|
|
<<Self as Gettable<T>>::Builder>::build();
|
|
|
}
|
|
|
|
|
@@ -510,40 +536,53 @@ impl<'sq, 'l, T: Entity, Col: EntityColumn<Entity = T>, Wrap: Gettable<'sq, 'l,
|
|
|
todo!()
|
|
|
}
|
|
|
|
|
|
- pub fn by<NCol: EntityColumn<Entity = T>>(self, col: &'sq NCol, data: &'sq dyn Modelable) -> ByClause<'sq, 'l, T, NCol, Self> {
|
|
|
- ByClause { wrap: self, col, data, _ghost: std::marker::PhantomData }
|
|
|
+ pub fn by<NCol: EntityColumn<Entity = T>>(
|
|
|
+ self,
|
|
|
+ col: &'sq NCol,
|
|
|
+ data: &'sq dyn Modelable,
|
|
|
+ ) -> ByClause<'sq, 'l, T, NCol, Self> {
|
|
|
+ ByClause {
|
|
|
+ wrap: self,
|
|
|
+ col,
|
|
|
+ data,
|
|
|
+ _ghost: std::marker::PhantomData,
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
impl<'l> QueryInterface<'l> {
|
|
|
- // pub fn get<'q, T: Entity>(&'q self) -> GetQuery<T> where 'q: 'l {
|
|
|
- pub fn get<'sq, T: Entity>(&'sq self) -> GetQuery<T> where 'sq: 'l {
|
|
|
- GetQuery::<'sq, 'l, _> { qi: self, _ghost: std::marker::PhantomData }
|
|
|
+ pub fn get<'sq, T: Entity>(&'sq self) -> GetQuery<T>
|
|
|
+ where
|
|
|
+ 'l: 'sq,
|
|
|
+ {
|
|
|
+ GetQuery::<'sq, 'l, _> {
|
|
|
+ qi: self,
|
|
|
+ _ghost: std::marker::PhantomData,
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod get_test {
|
|
|
use microrm_macros::Entity;
|
|
|
- use serde::{Serialize, Deserialize};
|
|
|
+ use serde::{Deserialize, Serialize};
|
|
|
|
|
|
use crate::QueryInterface;
|
|
|
|
|
|
-
|
|
|
#[derive(Entity, Serialize, Deserialize)]
|
|
|
#[microrm_internal]
|
|
|
pub struct KVStore {
|
|
|
key: String,
|
|
|
- value: String
|
|
|
+ value: String,
|
|
|
}
|
|
|
|
|
|
fn simple_test<'sq, 'l>(qi: &'sq QueryInterface<'l>) {
|
|
|
- let g = qi.get::<'sq, KVStore>();
|
|
|
+ // let g = qi.get::<'sq, KVStore>();
|
|
|
// qi.get::<'l,'_,KVStore>();
|
|
|
|
|
|
- //let t = g.by(&KVStore::Key, &"test");
|
|
|
+ // let t = g.by(&KVStore::Key, &"test").one();
|
|
|
+
|
|
|
//drop(t);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
@@ -553,8 +592,7 @@ mod get_test {
|
|
|
|
|
|
simple_test(&qi);
|
|
|
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+ {}
|
|
|
}
|
|
|
}
|
|
|
+*/
|