diff --git a/quaint/src/visitor/mysql.rs b/quaint/src/visitor/mysql.rs index 77979b8b7f6..63ed01612e0 100644 --- a/quaint/src/visitor/mysql.rs +++ b/quaint/src/visitor/mysql.rs @@ -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(" = ")?; diff --git a/quaint/src/visitor/postgres.rs b/quaint/src/visitor/postgres.rs index c119ab319de..d347402f73f 100644 --- a/quaint/src/visitor/postgres.rs +++ b/quaint/src/visitor/postgres.rs @@ -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()) { diff --git a/quaint/src/visitor/sqlite.rs b/quaint/src/visitor/sqlite.rs index 7292aa2eca6..06d7c86f987 100644 --- a/quaint/src/visitor/sqlite.rs +++ b/quaint/src/visitor/sqlite.rs @@ -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>>) -> visitor::Result { if let Some(returning) = returning { if !returning.is_empty() { diff --git a/query-engine/driver-adapters/src/queryable.rs b/query-engine/driver-adapters/src/queryable.rs index 7746d6137f1..9c64b48ba82 100644 --- a/query-engine/driver-adapters/src/queryable.rs +++ b/query-engine/driver-adapters/src/queryable.rs @@ -130,9 +130,25 @@ impl QuaintQueryable for JsBaseQueryable { .await } + // Note: Needed by the Wasm Schema Engine only. async fn version(&self) -> quaint::Result> { - // 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 {