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(driver-adapters): add "version()" support to QuaintQueryable #5103

Merged
merged 3 commits into from
Jan 7, 2025
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
5 changes: 5 additions & 0 deletions quaint/src/visitor/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub struct Mysql<'a> {
}

impl<'a> Mysql<'a> {
/// Name of the function used to view the version of the database.
pub const fn version_fn() -> &'static str {
"version"
}

fn visit_regular_equality_comparison(&mut self, left: Expression<'a>, right: Expression<'a>) -> visitor::Result {
self.visit_expression(left)?;
self.write(" = ")?;
Expand Down
5 changes: 5 additions & 0 deletions quaint/src/visitor/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ pub struct Postgres<'a> {
}

impl<'a> Postgres<'a> {
/// Name of the function used to view the version of the database.
pub const fn version_fn() -> &'static str {
"version"
}

fn visit_json_build_obj_expr(&mut self, expr: Expression<'a>) -> crate::Result<()> {
match expr.kind() {
ExpressionKind::Column(col) => match (col.type_family.as_ref(), col.native_type.as_deref()) {
Expand Down
5 changes: 5 additions & 0 deletions quaint/src/visitor/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ pub struct Sqlite<'a> {
}

impl<'a> Sqlite<'a> {
/// Name of the function used to view the version of the database.
pub const fn version_fn() -> &'static str {
"sqlite_version"
}

fn returning(&mut self, returning: Option<Vec<Column<'a>>>) -> visitor::Result {
if let Some(returning) = returning {
if !returning.is_empty() {
Expand Down
20 changes: 18 additions & 2 deletions query-engine/driver-adapters/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,25 @@ impl QuaintQueryable for JsBaseQueryable {
.await
}

// Note: Needed by the Wasm Schema Engine only.
async fn version(&self) -> quaint::Result<Option<String>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this call might be covered in some existing schema engine test, but I think it might be worth writing a basic explicit test case to ensure it works

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't any infra to run Driver Adapters in Schema Engine tests right now, so this cannot be achieved currently. But in principle, I'd agree with you :)

// Note: JS Connectors don't use this method.
Ok(None)
let version_fn: &'static str = match self.provider {
#[cfg(feature = "mysql")]
AdapterFlavour::Mysql => visitor::Mysql::version_fn(),
#[cfg(feature = "postgresql")]
AdapterFlavour::Postgres => visitor::Postgres::version_fn(),
#[cfg(feature = "sqlite")]
AdapterFlavour::Sqlite => visitor::Sqlite::version_fn(),
};

let query = format!(r#"SELECT {}() AS version"#, version_fn);
let rows = self.query_raw(query.as_str(), &[]).await?;

let version_string = rows
.first()
.and_then(|row| row.get("version").and_then(|version| version.to_string()));

Ok(version_string)
}

fn is_healthy(&self) -> bool {
Expand Down
Loading