mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 20:44:23 +01:00
add Query::Placeholder
This commit is contained in:
@@ -195,6 +195,7 @@ impl InteractionPlan {
|
||||
Query::Begin(_) => stats.begin_count += 1,
|
||||
Query::Commit(_) => stats.commit_count += 1,
|
||||
Query::Rollback(_) => stats.rollback_count += 1,
|
||||
Query::Placeholder => {}
|
||||
}
|
||||
}
|
||||
for interactions in &self.plan {
|
||||
@@ -766,6 +767,11 @@ impl InteractionType {
|
||||
|
||||
pub(crate) fn execute_query(&self, conn: &mut Arc<Connection>) -> ResultSet {
|
||||
if let Self::Query(query) = self {
|
||||
assert!(
|
||||
!matches!(query, Query::Placeholder),
|
||||
"simulation cannot have a placeholder Query for execution"
|
||||
);
|
||||
|
||||
let query_str = query.to_string();
|
||||
let rows = conn.query(&query_str);
|
||||
if rows.is_err() {
|
||||
|
||||
@@ -111,6 +111,9 @@ impl QueryDiscriminants {
|
||||
| QueryDiscriminants::Rollback => {
|
||||
unreachable!("transactional queries should not be generated")
|
||||
}
|
||||
QueryDiscriminants::Placeholder => {
|
||||
unreachable!("Query Placeholders should not be generated")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,6 +131,9 @@ impl QueryDiscriminants {
|
||||
| QueryDiscriminants::Rollback => {
|
||||
unreachable!("transactional queries should not be generated")
|
||||
}
|
||||
QueryDiscriminants::Placeholder => {
|
||||
unreachable!("Query Placeholders should not be generated")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ pub enum Query {
|
||||
Begin(Begin),
|
||||
Commit(Commit),
|
||||
Rollback(Rollback),
|
||||
/// Placeholder query that still needs to be generated
|
||||
Placeholder,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
@@ -70,6 +72,7 @@ impl Query {
|
||||
IndexSet::from_iter([table_name.clone()])
|
||||
}
|
||||
Query::Begin(_) | Query::Commit(_) | Query::Rollback(_) => IndexSet::new(),
|
||||
Query::Placeholder => IndexSet::new(),
|
||||
}
|
||||
}
|
||||
pub fn uses(&self) -> Vec<String> {
|
||||
@@ -83,6 +86,7 @@ impl Query {
|
||||
| Query::Drop(Drop { table, .. }) => vec![table.clone()],
|
||||
Query::CreateIndex(CreateIndex { table_name, .. }) => vec![table_name.clone()],
|
||||
Query::Begin(..) | Query::Commit(..) | Query::Rollback(..) => vec![],
|
||||
Query::Placeholder => vec![],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +120,7 @@ impl Display for Query {
|
||||
Self::Begin(begin) => write!(f, "{begin}"),
|
||||
Self::Commit(commit) => write!(f, "{commit}"),
|
||||
Self::Rollback(rollback) => write!(f, "{rollback}"),
|
||||
Self::Placeholder => Ok(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +129,6 @@ impl Shadow for Query {
|
||||
type Result = anyhow::Result<Vec<Vec<SimValue>>>;
|
||||
|
||||
fn shadow(&self, env: &mut ShadowTablesMut) -> Self::Result {
|
||||
tracing::info!("SHADOW {:?}", self);
|
||||
match self {
|
||||
Query::Create(create) => create.shadow(env),
|
||||
Query::Insert(insert) => insert.shadow(env),
|
||||
@@ -136,6 +140,7 @@ impl Shadow for Query {
|
||||
Query::Begin(begin) => Ok(begin.shadow(env)),
|
||||
Query::Commit(commit) => Ok(commit.shadow(env)),
|
||||
Query::Rollback(rollback) => Ok(rollback.shadow(env)),
|
||||
Query::Placeholder => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,6 +187,9 @@ impl From<QueryDiscriminants> for QueryCapabilities {
|
||||
| QueryDiscriminants::Rollback => {
|
||||
unreachable!("QueryCapabilities do not apply to transaction queries")
|
||||
}
|
||||
QueryDiscriminants::Placeholder => {
|
||||
unreachable!("QueryCapabilities do not apply to query Placeholder")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,6 +368,9 @@ fn execute_query_rusqlite(
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
Query::Placeholder => {
|
||||
unreachable!("simulation cannot have a placeholder Query for execution")
|
||||
}
|
||||
_ => {
|
||||
connection.execute(query.to_string().as_str(), ())?;
|
||||
Ok(vec![])
|
||||
|
||||
Reference in New Issue
Block a user