feat: add entity.subclass index to db schema
This commit is contained in:
@@ -25,65 +25,59 @@ fn from_condition(
|
|||||||
) -> Result<String, FailedTo> {
|
) -> Result<String, FailedTo> {
|
||||||
let fragment = match (comparison, condition) {
|
let fragment = match (comparison, condition) {
|
||||||
// BOOL
|
// BOOL
|
||||||
(Comparison::Equal, Condition::Bool(_)) => compose_fragment(name, "value_bool", "=", i + 1),
|
(Comparison::Equal, Condition::Bool(_)) => compose_fragment(name, "value_bool", "=", i),
|
||||||
(_, Condition::Bool(_)) => return Err(FailedTo::ComposeFilter),
|
(_, Condition::Bool(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
// SIGNED INT
|
// SIGNED INT
|
||||||
(Comparison::Equal, Condition::SignedInt(_)) => {
|
(Comparison::Equal, Condition::SignedInt(_)) => compose_fragment(name, "value_int", "=", i),
|
||||||
compose_fragment(name, "value_int", "=", i + 1)
|
|
||||||
}
|
|
||||||
(Comparison::Greater, Condition::SignedInt(_)) => {
|
(Comparison::Greater, Condition::SignedInt(_)) => {
|
||||||
compose_fragment(name, "value_int", ">", i + 1)
|
compose_fragment(name, "value_int", ">", i)
|
||||||
}
|
}
|
||||||
(Comparison::Lesser, Condition::SignedInt(_)) => {
|
(Comparison::Lesser, Condition::SignedInt(_)) => {
|
||||||
compose_fragment(name, "value_int", "<", i + 1)
|
compose_fragment(name, "value_int", "<", i)
|
||||||
}
|
}
|
||||||
(Comparison::GreaterOrEqual, Condition::SignedInt(_)) => {
|
(Comparison::GreaterOrEqual, Condition::SignedInt(_)) => {
|
||||||
compose_fragment(name, "value_int", ">=", i + 1)
|
compose_fragment(name, "value_int", ">=", i)
|
||||||
}
|
}
|
||||||
(Comparison::LesserOrEqual, Condition::SignedInt(_)) => {
|
(Comparison::LesserOrEqual, Condition::SignedInt(_)) => {
|
||||||
compose_fragment(name, "value_int", "<=", i + 1)
|
compose_fragment(name, "value_int", "<=", i)
|
||||||
}
|
}
|
||||||
(_, Condition::SignedInt(_)) => return Err(FailedTo::ComposeFilter),
|
(_, Condition::SignedInt(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
// UNSIGNED INT
|
// UNSIGNED INT
|
||||||
(Comparison::Equal, Condition::UnsignedInt(_)) => {
|
(Comparison::Equal, Condition::UnsignedInt(_)) => {
|
||||||
compose_fragment(name, "value_uint", "=", i + 1)
|
compose_fragment(name, "value_uint", "=", i)
|
||||||
}
|
}
|
||||||
(Comparison::Greater, Condition::UnsignedInt(_)) => {
|
(Comparison::Greater, Condition::UnsignedInt(_)) => {
|
||||||
compose_fragment(name, "value_uint", ">", i + 1)
|
compose_fragment(name, "value_uint", ">", i)
|
||||||
}
|
}
|
||||||
(Comparison::Lesser, Condition::UnsignedInt(_)) => {
|
(Comparison::Lesser, Condition::UnsignedInt(_)) => {
|
||||||
compose_fragment(name, "value_uint", "<", i + 1)
|
compose_fragment(name, "value_uint", "<", i)
|
||||||
}
|
}
|
||||||
(Comparison::GreaterOrEqual, Condition::UnsignedInt(_)) => {
|
(Comparison::GreaterOrEqual, Condition::UnsignedInt(_)) => {
|
||||||
compose_fragment(name, "value_uint", ">=", i + 1)
|
compose_fragment(name, "value_uint", ">=", i)
|
||||||
}
|
}
|
||||||
(Comparison::LesserOrEqual, Condition::UnsignedInt(_)) => {
|
(Comparison::LesserOrEqual, Condition::UnsignedInt(_)) => {
|
||||||
compose_fragment(name, "value_uint", "<=", i + 1)
|
compose_fragment(name, "value_uint", "<=", i)
|
||||||
}
|
}
|
||||||
(_, Condition::UnsignedInt(_)) => return Err(FailedTo::ComposeFilter),
|
(_, Condition::UnsignedInt(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
// REAL
|
// REAL
|
||||||
(Comparison::Equal, Condition::Real(_)) => compose_fragment(name, "value_real", "=", i + 1),
|
(Comparison::Equal, Condition::Real(_)) => compose_fragment(name, "value_real", "=", i),
|
||||||
(Comparison::Greater, Condition::Real(_)) => {
|
(Comparison::Greater, Condition::Real(_)) => compose_fragment(name, "value_real", ">", i),
|
||||||
compose_fragment(name, "value_real", ">", i + 1)
|
(Comparison::Lesser, Condition::Real(_)) => compose_fragment(name, "value_real", "<", i),
|
||||||
}
|
|
||||||
(Comparison::Lesser, Condition::Real(_)) => {
|
|
||||||
compose_fragment(name, "value_real", "<", i + 1)
|
|
||||||
}
|
|
||||||
(Comparison::GreaterOrEqual, Condition::Real(_)) => {
|
(Comparison::GreaterOrEqual, Condition::Real(_)) => {
|
||||||
compose_fragment(name, "value_real", ">=", i + 1)
|
compose_fragment(name, "value_real", ">=", i)
|
||||||
}
|
}
|
||||||
(Comparison::LesserOrEqual, Condition::Real(_)) => {
|
(Comparison::LesserOrEqual, Condition::Real(_)) => {
|
||||||
compose_fragment(name, "value_real", "<=", i + 1)
|
compose_fragment(name, "value_real", "<=", i)
|
||||||
}
|
}
|
||||||
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
|
(_, Condition::Real(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
// TEXT
|
// TEXT
|
||||||
(Comparison::IsExactly, Condition::Text(_)) => {
|
(Comparison::IsExactly, Condition::Text(_)) => {
|
||||||
compose_fragment(name, "value_text", "LIKE", i + 1)
|
compose_fragment(name, "value_text", "LIKE", i)
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
Comparison::StartsWith | Comparison::EndsWith | Comparison::Contains,
|
Comparison::StartsWith | Comparison::EndsWith | Comparison::Contains,
|
||||||
Condition::Text(_),
|
Condition::Text(_),
|
||||||
) => compose_fragment(name, "value_text", "LIKE", i + 1),
|
) => compose_fragment(name, "value_text", "LIKE", i),
|
||||||
(_, Condition::Text(_)) => return Err(FailedTo::ComposeFilter),
|
(_, Condition::Text(_)) => return Err(FailedTo::ComposeFilter),
|
||||||
};
|
};
|
||||||
Ok(fragment)
|
Ok(fragment)
|
||||||
@@ -95,8 +89,8 @@ pub fn run(filter: &Filter) -> Result<String, FailedTo> {
|
|||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
// for each condition add an inner join fragment
|
// for each condition add an inner join fragment
|
||||||
for (i, (name, comparison, condition)) in filter.conditions().enumerate() {
|
for (i, (name, comparison, condition)) in filter.conditions().enumerate() {
|
||||||
idx = i;
|
idx = i + 1;
|
||||||
let fragment = from_condition(i, name, comparison, condition)?;
|
let fragment = from_condition(idx, name, comparison, condition)?;
|
||||||
statement.push_str(&fragment);
|
statement.push_str(&fragment);
|
||||||
}
|
}
|
||||||
// add a neutral where condition
|
// add a neutral where condition
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ pub fn run(path: &path::Path) -> result::Result<(), FailedTo> {
|
|||||||
CONSTRAINT fk_entity_id FOREIGN KEY (entity_id) REFERENCES entity (id) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT fk_entity_id FOREIGN KEY (entity_id) REFERENCES entity (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
);
|
);
|
||||||
CREATE INDEX IF NOT EXISTS entity_class ON entity (class);
|
CREATE INDEX IF NOT EXISTS entity_class ON entity (class);
|
||||||
|
CREATE INDEX IF NOT EXISTS entity_subclass ON entity (subclass);
|
||||||
CREATE INDEX IF NOT EXISTS attribute_id ON attribute (id);
|
CREATE INDEX IF NOT EXISTS attribute_id ON attribute (id);
|
||||||
"#;
|
"#;
|
||||||
let connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
let connection = Connection::open(path).map_err(|_| sqlite::FailedTo::OpenConnection)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user