Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(qe): enable queries with returning for sqlite #4640

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Connector
NativeUpsert |
FilteredInlineChildNestedToOneDisconnect |
RowIn |
// InsertReturning, DeleteReturning, UpdateReturning - While SQLite does support RETURNING, it does not return column information on the
// way back from the database. This column type information is necessary in order to preserve consistency for some data types such as int,
// where values could overflow.
// Since we care to stay consistent with reads, it is not enabled.
InsertReturning |
DeleteReturning |
UpdateReturning |
SupportsFiltersOnRelationsWithoutJoins
});

Expand Down
35 changes: 35 additions & 0 deletions quaint/src/visitor/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,41 @@ impl<'a> Visitor<'a> for Sqlite<'a> {

Ok(())
}

fn visit_update(&mut self, update: Update<'a>) -> visitor::Result {
self.write("UPDATE ")?;
self.visit_table(update.table, true)?;

{
self.write(" SET ")?;
let pairs = update.columns.into_iter().zip(update.values);
let len = pairs.len();

for (i, (key, value)) in pairs.enumerate() {
self.visit_column(key)?;
self.write(" = ")?;
self.visit_expression(value)?;

if i < (len - 1) {
self.write(", ")?;
}
}
}

if let Some(conditions) = update.conditions {
self.write(" WHERE ")?;
self.visit_conditions(conditions)?;
}

self.returning(update.returning)?;

if let Some(comment) = update.comment {
self.write(" ")?;
self.visit_comment(comment)?;
}

Ok(())
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod metrics {
let total_operations = get_counter(&json, PRISMA_CLIENT_QUERIES_TOTAL);

match runner.connector_version() {
Sqlite(_) => assert_eq!(total_queries, 9),
Sqlite(_) => assert_eq!(total_queries, 2),
SqlServer(_) => assert_eq!(total_queries, 17),
MongoDb(_) => assert_eq!(total_queries, 5),
CockroachDb(_) => (), // not deterministic
Expand Down
Loading