diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/sqlite/connection.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/sqlite/connection.rs index 995a86e87c97..a34cca5cb9e1 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/sqlite/connection.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/sqlite/connection.rs @@ -24,6 +24,7 @@ impl Connection { } pub(super) async fn describe_schema(&mut self) -> ConnectorResult { + // Note: this relies on quaint::connector::rusqlite::Connection, which is exposed by `quaint/expose-drivers`, and is not Wasm-compatible. describer::SqlSchemaDescriber::new(&self.0) .describe_impl() .await diff --git a/schema-engine/sql-introspection-tests/Cargo.toml b/schema-engine/sql-introspection-tests/Cargo.toml index d0891b0bbaaa..dce7a5982147 100644 --- a/schema-engine/sql-introspection-tests/Cargo.toml +++ b/schema-engine/sql-introspection-tests/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" [dependencies] schema-connector = { path = "../connectors/schema-connector" } sql-schema-connector = { path = "../connectors/sql-schema-connector" } -sql-schema-describer = { path = "../sql-schema-describer" } +sql-schema-describer = { path = "../sql-schema-describer", features = [ + "all-native", +] } psl = { workspace = true, features = ["all"] } test-macros = { path = "../../libs/test-macros" } user-facing-errors = { path = "../../libs/user-facing-errors", features = [ diff --git a/schema-engine/sql-migration-tests/Cargo.toml b/schema-engine/sql-migration-tests/Cargo.toml index 6a345a365486..b2b3646ef2ef 100644 --- a/schema-engine/sql-migration-tests/Cargo.toml +++ b/schema-engine/sql-migration-tests/Cargo.toml @@ -7,7 +7,9 @@ edition = "2021" psl = { workspace = true, features = ["all"] } schema-core = { path = "../core" } sql-schema-connector = { path = "../connectors/sql-schema-connector" } -sql-schema-describer = { path = "../sql-schema-describer" } +sql-schema-describer = { path = "../sql-schema-describer", features = [ + "all-native", +] } user-facing-errors = { path = "../../libs/user-facing-errors", features = [ "all-native", ] } diff --git a/schema-engine/sql-schema-describer/Cargo.toml b/schema-engine/sql-schema-describer/Cargo.toml index 17b8eae63684..e1e15c0b0748 100644 --- a/schema-engine/sql-schema-describer/Cargo.toml +++ b/schema-engine/sql-schema-describer/Cargo.toml @@ -3,6 +3,12 @@ edition = "2021" name = "sql-schema-describer" version = "0.1.0" +[features] +sqlite-native = ["quaint/pooled", "quaint/sqlite-native", "quaint/expose-drivers"] +all-native = [ + "sqlite-native", +] + [dependencies] prisma-value = { path = "../../libs/prisma-value" } psl = { workspace = true, features = ["all"] } @@ -20,9 +26,6 @@ tracing.workspace = true tracing-error = "0.2" tracing-futures.workspace = true quaint = { workspace = true, features = [ - "all-native", - "pooled", - "expose-drivers", "fmt-sql", ] } diff --git a/schema-engine/sql-schema-describer/src/sqlite.rs b/schema-engine/sql-schema-describer/src/sqlite.rs index c130a7aa68ed..d86b7892e28b 100644 --- a/schema-engine/sql-schema-describer/src/sqlite.rs +++ b/schema-engine/sql-schema-describer/src/sqlite.rs @@ -9,12 +9,14 @@ use either::Either; use indexmap::IndexMap; use quaint::{ ast::{Value, ValueType}, - connector::{ColumnType as QuaintColumnType, GetRow, ToColumnNames}, prelude::ResultRow, }; use std::{any::type_name, borrow::Cow, collections::BTreeMap, convert::TryInto, fmt::Debug, path::Path}; use tracing::trace; +#[cfg(feature = "sqlite-native")] +pub(crate) mod native; + #[async_trait::async_trait] pub trait Connection { async fn query_raw<'a>( @@ -24,31 +26,6 @@ pub trait Connection { ) -> quaint::Result; } -#[async_trait::async_trait] -impl Connection for std::sync::Mutex { - async fn query_raw<'a>( - &'a self, - sql: &'a str, - params: &'a [quaint::prelude::Value<'a>], - ) -> quaint::Result { - let conn = self.lock().unwrap(); - let mut stmt = conn.prepare_cached(sql)?; - let column_types = stmt.columns().iter().map(QuaintColumnType::from).collect::>(); - let mut rows = stmt.query(quaint::connector::rusqlite::params_from_iter(params.iter()))?; - let column_names = rows.to_column_names(); - let mut converted_rows = Vec::new(); - while let Some(row) = rows.next()? { - converted_rows.push(row.get_result_row().unwrap()); - } - - Ok(quaint::prelude::ResultSet::new( - column_names, - column_types, - converted_rows, - )) - } -} - #[async_trait::async_trait] impl Connection for quaint::single::Quaint { async fn query_raw<'a>( diff --git a/schema-engine/sql-schema-describer/src/sqlite/native/mod.rs b/schema-engine/sql-schema-describer/src/sqlite/native/mod.rs new file mode 100644 index 000000000000..3f70a3f4f166 --- /dev/null +++ b/schema-engine/sql-schema-describer/src/sqlite/native/mod.rs @@ -0,0 +1,23 @@ +use crate::sqlite::Connection; + +use quaint::{ + connector::{rusqlite, ColumnType as QuaintColumnType, GetRow, ToColumnNames}, + prelude::{ResultSet, Value}, +}; + +#[async_trait::async_trait] +impl Connection for std::sync::Mutex { + async fn query_raw<'a>(&'a self, sql: &'a str, params: &'a [Value<'a>]) -> quaint::Result { + let conn = self.lock().unwrap(); + let mut stmt = conn.prepare_cached(sql)?; + let column_types = stmt.columns().iter().map(QuaintColumnType::from).collect::>(); + let mut rows = stmt.query(rusqlite::params_from_iter(params.iter()))?; + let column_names = rows.to_column_names(); + let mut converted_rows = Vec::new(); + while let Some(row) = rows.next()? { + converted_rows.push(row.get_result_row().unwrap()); + } + + Ok(ResultSet::new(column_names, column_types, converted_rows)) + } +}