diff --git a/schema-engine/connectors/sql-schema-connector/Cargo.toml b/schema-engine/connectors/sql-schema-connector/Cargo.toml index a336495e743..9fd005dcd08 100644 --- a/schema-engine/connectors/sql-schema-connector/Cargo.toml +++ b/schema-engine/connectors/sql-schema-connector/Cargo.toml @@ -22,7 +22,9 @@ indexmap.workspace = true prisma-value = { path = "../../../libs/prisma-value" } schema-connector = { path = "../schema-connector" } -sql-schema-describer = { path = "../../sql-schema-describer" } +sql-schema-describer = { path = "../../sql-schema-describer", features = [ + "all-native", +] } datamodel-renderer = { path = "../../datamodel-renderer" } sql-ddl = { path = "../../../libs/sql-ddl" } user-facing-errors = { path = "../../../libs/user-facing-errors", features = [ diff --git a/schema-engine/sql-schema-describer/Cargo.toml b/schema-engine/sql-schema-describer/Cargo.toml index e1e15c0b074..46279979e4f 100644 --- a/schema-engine/sql-schema-describer/Cargo.toml +++ b/schema-engine/sql-schema-describer/Cargo.toml @@ -4,9 +4,22 @@ name = "sql-schema-describer" version = "0.1.0" [features] -sqlite-native = ["quaint/pooled", "quaint/sqlite-native", "quaint/expose-drivers"] +postgresql = ["psl/postgresql", "quaint/postgresql"] +postgresql-native = ["postgresql", "quaint/pooled"] +sqlite = ["psl/sqlite", "quaint/sqlite"] +sqlite-native = ["sqlite", "quaint/pooled", "quaint/sqlite-native", "quaint/expose-drivers"] +mysql = ["psl/mysql", "quaint/mysql"] +mysql-native = ["mysql", "quaint/pooled"] +mssql = ["psl/mssql", "quaint/mssql"] +mssql-native = ["mssql", "quaint/pooled"] +cockroachdb = ["psl/cockroachdb", "quaint/postgresql"] +cockroachdb-native = ["cockroachdb", "quaint/pooled"] all-native = [ + "postgresql-native", "sqlite-native", + "mysql-native", + "mssql-native", + "cockroachdb-native", ] [dependencies] diff --git a/schema-engine/sql-schema-describer/src/sqlite.rs b/schema-engine/sql-schema-describer/src/sqlite.rs index d86b7892e28..65820728378 100644 --- a/schema-engine/sql-schema-describer/src/sqlite.rs +++ b/schema-engine/sql-schema-describer/src/sqlite.rs @@ -2,8 +2,7 @@ use crate::{ getters::Getter, ids::*, parsers::Parser, Column, ColumnArity, ColumnType, ColumnTypeFamily, DefaultValue, - DescriberResult, ForeignKeyAction, Lazy, PrismaValue, Regex, SQLSortOrder, SqlMetadata, SqlSchema, - SqlSchemaDescriberBackend, + DescriberResult, ForeignKeyAction, Lazy, PrismaValue, Regex, SQLSortOrder, SqlSchema, }; use either::Either; use indexmap::IndexMap; @@ -47,32 +46,6 @@ impl Debug for SqlSchemaDescriber<'_> { } } -#[async_trait::async_trait] -impl SqlSchemaDescriberBackend for SqlSchemaDescriber<'_> { - async fn list_databases(&self) -> DescriberResult> { - Ok(self.get_databases().await?) - } - - async fn get_metadata(&self, _schema: &str) -> DescriberResult { - let mut sql_schema = SqlSchema::default(); - let table_count = self.get_table_names(&mut sql_schema).await?.len(); - let size_in_bytes = self.get_size().await?; - - Ok(SqlMetadata { - table_count, - size_in_bytes, - }) - } - - async fn describe(&self, _schemas: &[&str]) -> DescriberResult { - self.describe_impl().await - } - - async fn version(&self) -> DescriberResult> { - Ok(Some(quaint::connector::sqlite_version().to_owned())) - } -} - impl Parser for SqlSchemaDescriber<'_> {} impl<'a> SqlSchemaDescriber<'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 index 3f70a3f4f16..df17da7a176 100644 --- a/schema-engine/sql-schema-describer/src/sqlite/native/mod.rs +++ b/schema-engine/sql-schema-describer/src/sqlite/native/mod.rs @@ -1,10 +1,12 @@ -use crate::sqlite::Connection; +use crate::{sqlite::Connection, DescriberResult, SqlMetadata, SqlSchema, SqlSchemaDescriberBackend}; use quaint::{ connector::{rusqlite, ColumnType as QuaintColumnType, GetRow, ToColumnNames}, prelude::{ResultSet, Value}, }; +use super::SqlSchemaDescriber; + #[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 { @@ -21,3 +23,29 @@ impl Connection for std::sync::Mutex { Ok(ResultSet::new(column_names, column_types, converted_rows)) } } + +#[async_trait::async_trait] +impl SqlSchemaDescriberBackend for SqlSchemaDescriber<'_> { + async fn list_databases(&self) -> DescriberResult> { + Ok(self.get_databases().await?) + } + + async fn get_metadata(&self, _schema: &str) -> DescriberResult { + let mut sql_schema = SqlSchema::default(); + let table_count = self.get_table_names(&mut sql_schema).await?.len(); + let size_in_bytes = self.get_size().await?; + + Ok(SqlMetadata { + table_count, + size_in_bytes, + }) + } + + async fn describe(&self, _schemas: &[&str]) -> DescriberResult { + self.describe_impl().await + } + + async fn version(&self) -> DescriberResult> { + Ok(Some(quaint::connector::sqlite_version().to_owned())) + } +}