|
@@ -1,10 +1,8 @@
|
|
|
use crate::entity::helpers::check_assoc;
|
|
|
use crate::schema::{AssocMap, IDWrap};
|
|
|
use crate::{
|
|
|
- entity::{
|
|
|
- Entity, EntityDatum, EntityDatumList, EntityDatumVisitor, EntityID, EntityPart,
|
|
|
- EntityPartList, EntityPartVisitor,
|
|
|
- },
|
|
|
+ datum::{Datum, DatumList, DatumVisitor},
|
|
|
+ entity::{Entity, EntityID, EntityPart, EntityPartList, EntityPartVisitor},
|
|
|
schema::{EntityMap, IDMap},
|
|
|
};
|
|
|
use crate::{DBError, DBResult};
|
|
@@ -113,8 +111,8 @@ pub(crate) fn select_by<E: Entity, PL: EntityPartList>(
|
|
|
by: &PL::DatumList,
|
|
|
) -> DBResult<Vec<IDWrap<E>>> {
|
|
|
struct HashDatumListTypes(std::collections::hash_map::DefaultHasher);
|
|
|
- impl EntityDatumVisitor for HashDatumListTypes {
|
|
|
- fn visit<ED: EntityDatum>(&mut self, _: &ED) {
|
|
|
+ impl DatumVisitor for HashDatumListTypes {
|
|
|
+ fn visit<ED: Datum>(&mut self, _: &ED) {
|
|
|
std::any::TypeId::of::<ED>().hash(&mut self.0);
|
|
|
}
|
|
|
}
|
|
@@ -139,13 +137,14 @@ pub(crate) fn select_by<E: Entity, PL: EntityPartList>(
|
|
|
}
|
|
|
PL::accept_part_visitor(&mut BuildConditions(&mut conditions));
|
|
|
|
|
|
- let table_name = format!("{}_{}", map.ctx(), E::entity_name());
|
|
|
+ // CTX let table_name = format!("{}_{}", map.ctx(), E::entity_name());
|
|
|
+ let table_name = format!("{}", E::entity_name());
|
|
|
format!("select rowid, * from `{}` where {}", table_name, conditions)
|
|
|
},
|
|
|
|stmt| {
|
|
|
struct BindDatum<'a, 'b>(&'a mut sqlite::Statement<'b>, usize);
|
|
|
- impl<'a, 'b> EntityDatumVisitor for BindDatum<'a, 'b> {
|
|
|
- fn visit<ED: EntityDatum>(&mut self, datum: &ED) {
|
|
|
+ impl<'a, 'b> DatumVisitor for BindDatum<'a, 'b> {
|
|
|
+ fn visit<ED: Datum>(&mut self, datum: &ED) {
|
|
|
datum.bind_to(self.0, self.1);
|
|
|
self.1 += 1
|
|
|
}
|
|
@@ -157,7 +156,10 @@ pub(crate) fn select_by<E: Entity, PL: EntityPartList>(
|
|
|
let mut rows = vec![];
|
|
|
while stmt.next()? == sqlite::State::Row {
|
|
|
let datum_list = <E::Parts>::build_datum_list(&map.conn(), map.ctx(), stmt)?;
|
|
|
- rows.push(IDWrap::new(<E::ID>::from_raw(stmt.read::<i64, _>(0)?), E::build(datum_list)));
|
|
|
+ rows.push(IDWrap::new(
|
|
|
+ <E::ID>::from_raw(stmt.read::<i64, _>(0)?),
|
|
|
+ E::build(datum_list),
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
stmt.reset()?;
|
|
@@ -174,7 +176,8 @@ pub(crate) fn insert<E: Entity>(
|
|
|
map.conn().with_prepared(
|
|
|
query_hash::<E>(map.ctx(), QueryType::Insert),
|
|
|
|| {
|
|
|
- let table_name = format!("{}_{}", map.ctx(), E::entity_name());
|
|
|
+ // CTX let table_name = format!("{}_{}", map.ctx(), E::entity_name());
|
|
|
+ let table_name = format!("{}", E::entity_name());
|
|
|
|
|
|
let mut part_names = String::new();
|
|
|
let mut placeholders = String::new();
|