Skip to content

Commit

Permalink
Merge branch 'main' into fix/cargo-build-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
janpio committed Nov 20, 2023
2 parents b0e8535 + 7025c28 commit 550a07f
Show file tree
Hide file tree
Showing 33 changed files with 369 additions and 60 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion quaint/src/connector/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! This module is only available with the `mssql` feature.
pub(crate) mod url;

pub use url::*;
pub use self::url::*;

#[cfg(feature = "mssql-native")]
pub(crate) mod native;
2 changes: 1 addition & 1 deletion quaint/src/connector/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
pub(crate) mod error;
pub(crate) mod url;

pub use self::url::*;
pub use error::MysqlError;
pub use url::*;

#[cfg(feature = "mysql-native")]
pub(crate) mod native;
2 changes: 1 addition & 1 deletion quaint/src/connector/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
pub(crate) mod error;
pub(crate) mod url;

pub use self::url::*;
pub use error::PostgresError;
pub use url::*;

#[cfg(feature = "postgresql-native")]
pub(crate) mod native;
32 changes: 13 additions & 19 deletions quaint/src/visitor/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,27 @@ impl<'a> Visitor<'a> for Postgres<'a> {
variants: Vec<EnumVariant<'a>>,
name: Option<EnumName<'a>>,
) -> visitor::Result {
let len = variants.len();

// Since enums are user-defined custom types, tokio-postgres fires an additional query
// when parameterizing values of type enum to know which custom type the value refers to.
// Casting the enum value to `TEXT` avoid this roundtrip since `TEXT` is a builtin type.
if let Some(enum_name) = name.clone() {
self.surround_with("ARRAY[", "]", |s| {
for (i, variant) in variants.into_iter().enumerate() {
s.add_parameter(variant.into_text());
s.parameter_substitution()?;
s.write("::text")?;

if i < (len - 1) {
s.write(", ")?;
}
self.add_parameter(Value::array(variants.into_iter().map(|v| v.into_text())));

self.surround_with("CAST(", ")", |s| {
s.parameter_substitution()?;
s.write("::text[]")?;
s.write(" AS ")?;

if let Some(schema_name) = enum_name.schema_name {
s.surround_with_backticks(schema_name.deref())?;
s.write(".")?
}

s.surround_with_backticks(enum_name.name.deref())?;
s.write("[]")?;

Ok(())
})?;

self.write("::")?;
if let Some(schema_name) = enum_name.schema_name {
self.surround_with_backticks(schema_name.deref())?;
self.write(".")?
}
self.surround_with_backticks(enum_name.name.deref())?;
self.write("[]")?;
} else {
self.visit_parameterized(Value::array(
variants.into_iter().map(|variant| variant.into_enum(name.clone())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod prisma_17103;
mod prisma_18517;
mod prisma_20799;
mod prisma_21369;
mod prisma_21901;
mod prisma_5952;
mod prisma_6173;
mod prisma_7010;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod conversion_error {
runner,
r#"query { findManyTestModel { field } }"#,
2023,
"Inconsistent column data: Conversion failed: number must be an integer in column 'field'"
"Inconsistent column data: Conversion failed: number must be an integer in column 'field', got '1.84467440724388e19'"
);

Ok(())
Expand Down Expand Up @@ -74,7 +74,7 @@ mod conversion_error {
runner,
r#"query { findManyTestModel { field } }"#,
2023,
"Inconsistent column data: Conversion failed: number must be an i64 in column 'field'"
"Inconsistent column data: Conversion failed: number must be an integer in column 'field', got '1.84467440724388e19'"
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use indoc::indoc;
use query_engine_tests::*;

#[test_suite(schema(schema), capabilities(Enums, ScalarLists), exclude(MongoDb))]
mod prisma_21901 {
fn schema() -> String {
let schema = indoc! {
r#"model Test {
#id(id, Int, @id)
colors Color[]
}
enum Color {
red
blue
green
}
"#
};

schema.to_owned()
}

// fixes https://github.com/prisma/prisma/issues/21901
#[connector_test]
async fn test(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(
runner,
r#"mutation { createOneTest(data: { id: 1, colors: ["red"] }) { colors } }"#
),
@r###"{"data":{"createOneTest":{"colors":["red"]}}}"###
);

insta::assert_snapshot!(
run_query!(runner, fmt_execute_raw(r#"TRUNCATE TABLE "prisma_21901_test"."Test" CASCADE;"#, [])),
@r###"{"data":{"executeRaw":0}}"###
);

insta::assert_snapshot!(
run_query!(
runner,
r#"mutation { createOneTest(data: { id: 2, colors: ["blue"] }) { colors } }"#
),
@r###"{"data":{"createOneTest":{"colors":["blue"]}}}"###
);

Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ once_cell = "1"
qe-setup = { path = "../qe-setup" }
request-handlers = { path = "../../request-handlers" }
tokio.workspace = true
query-core = { path = "../../core" }
query-core = { path = "../../core", features = ["metrics"] }
sql-query-connector = { path = "../../connectors/sql-query-connector" }
query-engine = { path = "../../query-engine"}
psl.workspace = true
Expand Down
11 changes: 9 additions & 2 deletions query-engine/connectors/sql-query-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ version = "0.1.0"

[features]
vendored-openssl = ["quaint/vendored-openssl"]

# Enable Driver Adapters
driver-adapters = []

[dependencies]
Expand All @@ -18,15 +20,20 @@ once_cell = "1.3"
rand = "0.7"
serde_json = {version = "1.0", features = ["float_roundtrip"]}
thiserror = "1.0"
tokio.workspace = true
tokio = { version = "1.0", features = ["macros", "time"] }
tracing = "0.1"
tracing-futures = "0.2"
uuid.workspace = true
opentelemetry = { version = "0.17", features = ["tokio"] }
tracing-opentelemetry = "0.17.3"
quaint.workspace = true
cuid = { git = "https://github.com/prisma/cuid-rust", branch = "wasm32-support" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
quaint.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
quaint = { path = "../../../quaint" }

[dependencies.connector-interface]
package = "query-connector"
path = "../query-connector"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(target_arch = "wasm32", allow(dead_code))]

use super::{catch, transaction::SqlConnectorTransaction};
use crate::{database::operations::*, Context, SqlError};
use async_trait::async_trait;
Expand Down
19 changes: 11 additions & 8 deletions query-engine/connectors/sql-query-connector/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
mod connection;
#[cfg(feature = "driver-adapters")]
mod js;
mod mssql;
mod mysql;
mod postgresql;
mod sqlite;
mod transaction;

#[cfg(not(target_arch = "wasm32"))]
pub(crate) mod native {
pub(crate) mod mssql;
pub(crate) mod mysql;
pub(crate) mod postgresql;
pub(crate) mod sqlite;
}

pub(crate) mod operations;

use async_trait::async_trait;
use connector_interface::{error::ConnectorError, Connector};

#[cfg(feature = "driver-adapters")]
pub use js::*;
pub use mssql::*;
pub use mysql::*;
pub use postgresql::*;
pub use sqlite::*;

#[cfg(not(target_arch = "wasm32"))]
pub use native::{mssql::*, mysql::*, postgresql::*, sqlite::*};

#[async_trait]
pub trait FromSource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::connection::SqlConnection;
use crate::database::{catch, connection::SqlConnection};
use crate::{FromSource, SqlError};
use async_trait::async_trait;
use connector_interface::{
Expand Down Expand Up @@ -60,7 +60,7 @@ impl FromSource for Mssql {
#[async_trait]
impl Connector for Mssql {
async fn get_connection<'a>(&'a self) -> connector::Result<Box<dyn Connection + Send + Sync + 'static>> {
super::catch(self.connection_info.clone(), async move {
catch(self.connection_info.clone(), async move {
let conn = self.pool.check_out().await.map_err(SqlError::from)?;
let conn = SqlConnection::new(conn, &self.connection_info, self.features);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::connection::SqlConnection;
use crate::database::{catch, connection::SqlConnection};
use crate::{FromSource, SqlError};
use async_trait::async_trait;
use connector_interface::{
Expand Down Expand Up @@ -65,7 +65,7 @@ impl FromSource for Mysql {
#[async_trait]
impl Connector for Mysql {
async fn get_connection<'a>(&'a self) -> connector::Result<Box<dyn Connection + Send + Sync + 'static>> {
super::catch(self.connection_info.clone(), async move {
catch(self.connection_info.clone(), async move {
let runtime_conn = self.pool.check_out().await?;

// Note: `runtime_conn` must be `Sized`, as that's required by `TransactionCapable`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::connection::SqlConnection;
use crate::database::{catch, connection::SqlConnection};
use crate::{FromSource, SqlError};
use async_trait::async_trait;
use connector_interface::{
Expand Down Expand Up @@ -67,7 +67,7 @@ impl FromSource for PostgreSql {
#[async_trait]
impl Connector for PostgreSql {
async fn get_connection<'a>(&'a self) -> connector_interface::Result<Box<dyn Connection + Send + Sync + 'static>> {
super::catch(self.connection_info.clone(), async move {
catch(self.connection_info.clone(), async move {
let conn = self.pool.check_out().await.map_err(SqlError::from)?;
let conn = SqlConnection::new(conn, &self.connection_info, self.features);
Ok(Box::new(conn) as Box<dyn Connection + Send + Sync + 'static>)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::connection::SqlConnection;
use crate::database::{catch, connection::SqlConnection};
use crate::{FromSource, SqlError};
use async_trait::async_trait;
use connector_interface::{
Expand Down Expand Up @@ -80,7 +80,7 @@ fn invalid_file_path_error(file_path: &str, connection_info: &ConnectionInfo) ->
#[async_trait]
impl Connector for Sqlite {
async fn get_connection<'a>(&'a self) -> connector::Result<Box<dyn Connection + Send + Sync + 'static>> {
super::catch(self.connection_info().clone(), async move {
catch(self.connection_info().clone(), async move {
let conn = self.pool.check_out().await.map_err(SqlError::from)?;
let conn = SqlConnection::new(conn, self.connection_info(), self.features);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,28 @@ use std::{
ops::Deref,
usize,
};
use tracing::log::trace;
use user_facing_errors::query_engine::DatabaseConstraint;

#[cfg(target_arch = "wasm32")]
macro_rules! trace {
(target: $target:expr, $($arg:tt)+) => {{
// No-op in WebAssembly
}};
($($arg:tt)+) => {{
// No-op in WebAssembly
}};
}

#[cfg(not(target_arch = "wasm32"))]
macro_rules! trace {
(target: $target:expr, $($arg:tt)+) => {
tracing::log::trace!(target: $target, $($arg)+);
};
($($arg:tt)+) => {
tracing::log::trace!($($arg)+);
};
}

async fn generate_id(
conn: &dyn Queryable,
id_field: &FieldSelection,
Expand Down
5 changes: 4 additions & 1 deletion query-engine/connectors/sql-query-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ mod value_ext;
use self::{column_metadata::*, context::Context, query_ext::QueryExt, row::*};
use quaint::prelude::Queryable;

pub use database::FromSource;
#[cfg(feature = "driver-adapters")]
pub use database::{activate_driver_adapter, Js};
pub use database::{FromSource, Mssql, Mysql, PostgreSql, Sqlite};
pub use error::SqlError;

#[cfg(not(target_arch = "wasm32"))]
pub use database::{Mssql, Mysql, PostgreSql, Sqlite};

type Result<T> = std::result::Result<T, error::SqlError>;
2 changes: 1 addition & 1 deletion query-engine/core-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
dissimilar = "1.0.4"
user-facing-errors = { path = "../../libs/user-facing-errors" }
request-handlers = { path = "../request-handlers" }
query-core = { path = "../core" }
query-core = { path = "../core", features = ["metrics"] }
schema = { path = "../schema" }
psl.workspace = true
serde_json.workspace = true
Loading

0 comments on commit 550a07f

Please sign in to comment.