|
@@ -43,6 +43,8 @@ impl<E: Entity> Queryable for TableComponent<E> {
|
|
|
type OutputContainer = Vec<Stored<E>>;
|
|
|
type StaticVersion = Self;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = false;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
Query::new()
|
|
|
.attach(QueryPart::Root, "SELECT DISTINCT")
|
|
@@ -91,6 +93,8 @@ impl<WEP: EntityPart, Parent: Queryable + 'static> Queryable
|
|
|
type OutputContainer = Option<Stored<WEP::Entity>>;
|
|
|
type StaticVersion = Self;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = Parent::IS_UNIQUE;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
unreachable!()
|
|
|
}
|
|
@@ -112,6 +116,8 @@ impl<
|
|
|
type OutputContainer = Parent::OutputContainer;
|
|
|
type StaticVersion = CanonicalWithComponent<WEP, Parent::StaticVersion>;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = Parent::IS_UNIQUE;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
self.parent.build().attach(
|
|
|
QueryPart::Where,
|
|
@@ -195,6 +201,8 @@ impl<E: Entity, Parent: Queryable + 'static, EPL: EntityPartList<Entity = E>> Qu
|
|
|
type OutputContainer = Option<Stored<E>>;
|
|
|
type StaticVersion = Self;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = Parent::IS_UNIQUE;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
unreachable!()
|
|
|
}
|
|
@@ -227,6 +235,8 @@ impl<
|
|
|
type OutputContainer = Option<Stored<E>>;
|
|
|
type StaticVersion = CanonicalIndexComponent<E, Parent::StaticVersion, EPL>;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = true;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
let mut query = self.parent.build();
|
|
|
|
|
@@ -285,8 +295,15 @@ impl<Parent: Queryable> Queryable for SingleComponent<Parent> {
|
|
|
type OutputContainer = Option<Stored<Self::EntityOutput>>;
|
|
|
type StaticVersion = SingleComponent<Parent::StaticVersion>;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = true;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
- self.parent.build().attach(QueryPart::Trailing, "LIMIT 1")
|
|
|
+ // it's not a crime to ask a second time, but it's not valid SQL to repeat the LIMIT 1, either
|
|
|
+ if Parent::IS_UNIQUE {
|
|
|
+ self.parent.build()
|
|
|
+ } else {
|
|
|
+ self.parent.build().attach(QueryPart::Trailing, "LIMIT 1")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
fn bind(&self, stmt: &mut StatementContext, index: &mut i32) {
|
|
@@ -339,6 +356,8 @@ impl<
|
|
|
type OutputContainer = Vec<Stored<R>>;
|
|
|
type StaticVersion = JoinComponent<R, L, EP, Parent::StaticVersion>;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = Parent::IS_UNIQUE;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
let remote_name = R::entity_name();
|
|
|
let local_name = L::entity_name();
|
|
@@ -444,6 +463,8 @@ impl<FE: Entity, EP: EntityPart, Parent: Queryable> Queryable for ForeignCompone
|
|
|
type OutputContainer =
|
|
|
<Parent::OutputContainer as OutputContainer<Parent::EntityOutput>>::ReplacedEntity<FE>;
|
|
|
|
|
|
+ const IS_UNIQUE: bool = Parent::IS_UNIQUE;
|
|
|
+
|
|
|
fn build(&self) -> Query {
|
|
|
let subquery = self.parent.build().replace(
|
|
|
QueryPart::Columns,
|