Skip to content

Commit

Permalink
fix(schema-engine-wasm): wasm compilation, move "SqlSchemaDescriberBa…
Browse files Browse the repository at this point in the history
…ckend" to sqlite-native impl
  • Loading branch information
jkomyno committed Jan 7, 2025
1 parent bd3416a commit 83a147f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
4 changes: 3 additions & 1 deletion schema-engine/connectors/sql-schema-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
15 changes: 14 additions & 1 deletion schema-engine/sql-schema-describer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
29 changes: 1 addition & 28 deletions schema-engine/sql-schema-describer/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,32 +46,6 @@ impl Debug for SqlSchemaDescriber<'_> {
}
}

#[async_trait::async_trait]
impl SqlSchemaDescriberBackend for SqlSchemaDescriber<'_> {
async fn list_databases(&self) -> DescriberResult<Vec<String>> {
Ok(self.get_databases().await?)
}

async fn get_metadata(&self, _schema: &str) -> DescriberResult<SqlMetadata> {
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<SqlSchema> {
self.describe_impl().await
}

async fn version(&self) -> DescriberResult<Option<String>> {
Ok(Some(quaint::connector::sqlite_version().to_owned()))
}
}

impl Parser for SqlSchemaDescriber<'_> {}

impl<'a> SqlSchemaDescriber<'a> {
Expand Down
30 changes: 29 additions & 1 deletion schema-engine/sql-schema-describer/src/sqlite/native/mod.rs
Original file line number Diff line number Diff line change
@@ -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<rusqlite::Connection> {
async fn query_raw<'a>(&'a self, sql: &'a str, params: &'a [Value<'a>]) -> quaint::Result<ResultSet> {
Expand All @@ -21,3 +23,29 @@ impl Connection for std::sync::Mutex<rusqlite::Connection> {
Ok(ResultSet::new(column_names, column_types, converted_rows))
}
}

#[async_trait::async_trait]
impl SqlSchemaDescriberBackend for SqlSchemaDescriber<'_> {
async fn list_databases(&self) -> DescriberResult<Vec<String>> {
Ok(self.get_databases().await?)
}

async fn get_metadata(&self, _schema: &str) -> DescriberResult<SqlMetadata> {
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<SqlSchema> {
self.describe_impl().await
}

async fn version(&self) -> DescriberResult<Option<String>> {
Ok(Some(quaint::connector::sqlite_version().to_owned()))
}
}

0 comments on commit 83a147f

Please sign in to comment.