Skip to content

Commit

Permalink
Add connector versions for js drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Nov 21, 2023
1 parent 2ea2782 commit bfe4811
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod metrics {
let total_operations = get_counter(&json, PRISMA_CLIENT_QUERIES_TOTAL);

match runner.connector_version() {
Sqlite => assert_eq!(total_queries, 9),
Sqlite(_) => assert_eq!(total_queries, 9),
SqlServer(_) => assert_eq!(total_queries, 17),
MongoDb(_) => assert_eq!(total_queries, 5),
CockroachDb(_) => (), // not deterministic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ mod order_by_dependent {
}
}"#,
// Depends on how null values are handled.
MongoDb(_) | Sqlite => vec![r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":null}},{"id":3,"b":null},{"id":1,"b":{"c":{"id":1}}}]}}"#],
MongoDb(_) | Sqlite(_) => vec![r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":null}},{"id":3,"b":null},{"id":1,"b":{"c":{"id":1}}}]}}"#],
SqlServer(_) => vec![r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":2,"b":{"c":null}},{"id":1,"b":{"c":{"id":1}}}]}}"#],
Postgres(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}},{"id":2,"b":{"c":null}},{"id":3,"b":null}]}}"#],
_ => vec![
Expand Down Expand Up @@ -243,7 +243,7 @@ mod order_by_dependent {
}
}
}"#,
MongoDb(_) | Sqlite => vec![r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#],
MongoDb(_) | Sqlite(_) => vec![r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#],
MySql(_) | CockroachDb(_) => vec![
r#"{"data":{"findManyModelA":[{"id":4,"b":null},{"id":3,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#,
r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#,
Expand Down Expand Up @@ -275,7 +275,7 @@ mod order_by_dependent {
}
}
}"#,
MongoDb(_) | Sqlite => vec![r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#],
MongoDb(_) | Sqlite(_)=> vec![r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#],
MySql(_) | CockroachDb(_) => vec![
r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":4,"b":null},{"id":3,"b":null}]}}"#,
r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod order_by_dependent_pag {
}
}"#,
// Depends on how null values are handled.
MongoDb(_) | Sqlite | MySql(_) | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}}]}}"#],
MongoDb(_) | Sqlite(_) | MySql(_) | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}}]}}"#],
_ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}},{"id":3,"b":null}]}}"#]
);

Expand Down Expand Up @@ -166,7 +166,7 @@ mod order_by_dependent_pag {
}
}"#,
// Depends on how null values are handled.
MongoDb(_) | Sqlite | MySql(_) | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}}]}}"#],
MongoDb(_) | Sqlite(_) | MySql(_) | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}}]}}"#],
_ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}},{"id":2,"b":{"c":null}},{"id":3,"b":null}]}}"#]
);

Expand Down Expand Up @@ -248,7 +248,7 @@ mod order_by_dependent_pag {
}
}"#,
// Depends on how null values are handled.
MongoDb(_) | MySql(_) | Sqlite | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#],
MongoDb(_) | MySql(_) | Sqlite(_) | CockroachDb(_) => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#],
_ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod views {
=> {
r#"CREATE VIEW TestView AS SELECT TestModel.*, CONCAT(TestModel.firstName, ' ', TestModel.lastName) AS "fullName" FROM TestModel"#.to_owned()
},
ConnectorVersion::Sqlite => {
ConnectorVersion::Sqlite(_) => {
r#"CREATE VIEW TestView AS SELECT TestModel.*, TestModel.firstName || ' ' || TestModel.lastName AS "fullName" FROM TestModel"#.to_owned()
}
ConnectorVersion::SqlServer(_) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub struct TestConfig {
#[derive(Debug, Default, Serialize, Deserialize)]
pub(crate) struct DriverAdapterConfig {
pub(crate) proxy_url: Option<String>,
pub(crate) connection_string_override: Option<String>,
}

const CONFIG_LOAD_FAILED: &str = r####"
Expand Down Expand Up @@ -199,7 +198,8 @@ impl TestConfig {
| Ok(ConnectorVersion::SqlServer(None))
| Ok(ConnectorVersion::MongoDb(None))
| Ok(ConnectorVersion::CockroachDb(None))
| Ok(ConnectorVersion::Postgres(None)) => {
| Ok(ConnectorVersion::Postgres(None))
| Ok(ConnectorVersion::Sqlite(None)) => {
exit_with_message("The current test connector requires a version to be set to run.");
}
Ok(ConnectorVersion::Vitess(Some(_)))
Expand All @@ -208,7 +208,7 @@ impl TestConfig {
| Ok(ConnectorVersion::MongoDb(Some(_)))
| Ok(ConnectorVersion::CockroachDb(Some(_)))
| Ok(ConnectorVersion::Postgres(Some(_)))
| Ok(ConnectorVersion::Sqlite) => (),
| Ok(ConnectorVersion::Sqlite(Some(_))) => (),
Err(err) => exit_with_message(&err.to_string()),
}

Expand Down Expand Up @@ -284,7 +284,7 @@ impl TestConfig {
ConnectorVersion::Postgres(_) => &PostgresConnectorTag,
ConnectorVersion::MySql(_) => &MySqlConnectorTag,
ConnectorVersion::MongoDb(_) => &MongoDbConnectorTag,
ConnectorVersion::Sqlite => &SqliteConnectorTag,
ConnectorVersion::Sqlite(_) => &SqliteConnectorTag,
ConnectorVersion::CockroachDb(_) => &CockroachDbConnectorTag,
ConnectorVersion::Vitess(_) => &VitessConnectorTag,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ pub(crate) fn connection_string(
is_multi_schema: bool,
isolation_level: Option<&'static str>,
) -> String {
if let Some(Some(connection_string)) = test_config
.driver_adapter_config
.as_ref()
.map(|c| c.connection_string_override.as_ref())
{
return connection_string
.to_owned()
.replace("{database}", database)
.replace("{isolation_level}", isolation_level.unwrap_or_default());
}

let is_ci = test_config.is_ci;
match version {
ConnectorVersion::SqlServer(v) => {
Expand Down Expand Up @@ -110,7 +99,7 @@ pub(crate) fn connection_string(
Some(PostgresVersion::V12) if is_ci => {
format!("postgresql://postgres:prisma@test-db-postgres-12:5432/{database}")
}
Some(PostgresVersion::V13) if is_ci => {
Some(PostgresVersion::V13) | Some(PostgresVersion::NeonJs) | Some(PostgresVersion::PgJs) if is_ci => {
format!("postgresql://postgres:prisma@test-db-postgres-13:5432/{database}")
}
Some(PostgresVersion::V14) if is_ci => {
Expand All @@ -127,7 +116,9 @@ pub(crate) fn connection_string(
Some(PostgresVersion::V10) => format!("postgresql://postgres:[email protected]:5432/{database}"),
Some(PostgresVersion::V11) => format!("postgresql://postgres:[email protected]:5433/{database}"),
Some(PostgresVersion::V12) => format!("postgresql://postgres:[email protected]:5434/{database}"),
Some(PostgresVersion::V13) => format!("postgresql://postgres:[email protected]:5435/{database}"),
Some(PostgresVersion::V13) | Some(PostgresVersion::NeonJs) | Some(PostgresVersion::PgJs) => {
format!("postgresql://postgres:[email protected]:5435/{database}")
}
Some(PostgresVersion::V14) => format!("postgresql://postgres:[email protected]:5437/{database}"),
Some(PostgresVersion::V15) => format!("postgresql://postgres:[email protected]:5438/{database}"),
Some(PostgresVersion::PgBouncer) => {
Expand Down Expand Up @@ -174,7 +165,7 @@ pub(crate) fn connection_string(
}
None => unreachable!("A versioned connector must have a concrete version to run."),
},
ConnectorVersion::Sqlite => {
ConnectorVersion::Sqlite(_) => {
let workspace_root = std::env::var("WORKSPACE_ROOT")
.unwrap_or_else(|_| ".".to_owned())
.trim_end_matches('/')
Expand Down Expand Up @@ -210,6 +201,10 @@ pub(crate) fn connection_string(
}

ConnectorVersion::Vitess(Some(VitessVersion::V8_0)) => "mysql://root@localhost:33807/test".into(),
ConnectorVersion::Vitess(Some(VitessVersion::PlanetscaleJs)) => {
format!("mysql://[email protected]:3310/{database}")
}

ConnectorVersion::Vitess(None) => unreachable!("A versioned connector must have a concrete version to run."),
}
}
Expand All @@ -222,7 +217,7 @@ pub enum ConnectorVersion {
Postgres(Option<PostgresVersion>),
MySql(Option<MySqlVersion>),
MongoDb(Option<MongoDbVersion>),
Sqlite,
Sqlite(Option<SqliteVersion>),
CockroachDb(Option<CockroachDbVersion>),
Vitess(Option<VitessVersion>),
}
Expand All @@ -245,14 +240,14 @@ impl ConnectorVersion {
(MongoDb(a), MongoDb(b)) => versions_match(a, b),
(CockroachDb(a), CockroachDb(b)) => versions_match(a, b),
(Vitess(a), Vitess(b)) => versions_match(a, b),
(Sqlite, Sqlite) => true,
(Sqlite(a), Sqlite(b)) => versions_match(a, b),

(MongoDb(..), _)
| (_, MongoDb(..))
| (SqlServer(..), _)
| (_, SqlServer(..))
| (Sqlite, _)
| (_, Sqlite)
| (Sqlite(..), _)
| (_, Sqlite(..))
| (CockroachDb(..), _)
| (_, CockroachDb(..))
| (Vitess(..), _)
Expand Down Expand Up @@ -282,7 +277,10 @@ impl fmt::Display for ConnectorVersion {
Some(v) => format!("MongoDB ({})", v.to_string()),
None => "MongoDB (unknown)".to_string(),
},
Self::Sqlite => "SQLite".to_string(),
Self::Sqlite(v) => match v {
Some(v) => format!("SQLite ({})", v.to_string()),
None => "SQLite (unknown)".to_string(),
},
Self::Vitess(v) => match v {
Some(v) => format!("Vitess ({v})"),
None => "Vitess (unknown)".to_string(),
Expand Down Expand Up @@ -353,7 +351,7 @@ impl TryFrom<(&str, Option<&str>)> for ConnectorVersion {
#[track_caller]
fn try_from((connector, version): (&str, Option<&str>)) -> Result<Self, Self::Error> {
Ok(match connector.to_lowercase().as_str() {
"sqlite" => ConnectorVersion::Sqlite,
"sqlite" => ConnectorVersion::Sqlite(version.map(SqliteVersion::try_from).transpose()?),
"sqlserver" => ConnectorVersion::SqlServer(version.map(SqlServerVersion::try_from).transpose()?),
"cockroachdb" => ConnectorVersion::CockroachDb(version.map(CockroachDbVersion::try_from).transpose()?),
"postgres" => ConnectorVersion::Postgres(version.map(PostgresVersion::try_from).transpose()?),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum PostgresVersion {
V14,
V15,
PgBouncer,
NeonJs,
PgJs,
}

impl TryFrom<&str> for PostgresVersion {
Expand All @@ -51,6 +53,8 @@ impl TryFrom<&str> for PostgresVersion {
"14" => Self::V14,
"15" => Self::V15,
"pgbouncer" => Self::PgBouncer,
"neon.js" => Self::NeonJs,
"pg.js" => Self::PgJs,
_ => return Err(TestError::parse_error(format!("Unknown Postgres version `{s}`"))),
};

Expand All @@ -69,6 +73,8 @@ impl ToString for PostgresVersion {
PostgresVersion::V14 => "14",
PostgresVersion::V15 => "15",
PostgresVersion::PgBouncer => "pgbouncer",
PostgresVersion::NeonJs => "neon.js",
PostgresVersion::PgJs => "pg.js",
}
.to_owned()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,37 @@ impl ConnectorTagInterface for SqliteConnectorTag {
psl::builtin_connectors::SQLITE.capabilities()
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SqliteVersion {
V3,
LibsqlJS,
}

impl Default for SqliteVersion {
fn default() -> Self {
Self::V3
}
}

impl fmt::Display for SqliteVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SqliteVersion::V3 => write!(f, "3"),
SqliteVersion::LibsqlJS => write!(f, "libsql.js"),
}
}
}

impl TryFrom<&str> for SqliteVersion {
type Error = TestError;

fn try_from(s: &str) -> Result<Self, Self::Error> {
let version = match s {
"3" => Self::V3,
"libsql.js" => Self::LibsqlJS,
_ => return Err(TestError::parse_error(format!("Unknown SQLite version `{s}`"))),
};
Ok(version)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ impl ConnectorTagInterface for VitessConnectorTag {
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum VitessVersion {
V8_0,
// The planetscale driver adapter
PlanetscaleJs,
}

impl FromStr for VitessVersion {
Expand All @@ -42,6 +44,7 @@ impl FromStr for VitessVersion {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let version = match s {
"8.0" => Self::V8_0,
"planetscale.js" => Self::PlanetscaleJs,
_ => return Err(TestError::parse_error(format!("Unknown Vitess version `{s}`"))),
};

Expand All @@ -53,6 +56,7 @@ impl Display for VitessVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::V8_0 => write!(f, "8.0"),
Self::PlanetscaleJs => write!(f, "planetscale.js"),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"connector": "postgres",
"version": "13",
"version": "neon.js",
"driver_adapter": "neon:ws",
"driver_adapter_config": { "proxy_url": "127.0.0.1:5488/v1" },
"external_test_executor": "default"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"connector": "postgres",
"version": "13",
"version": "pg.js",
"driver_adapter": "pg",
"external_test_executor": "default"
}
5 changes: 2 additions & 3 deletions query-engine/connector-test-kit-rs/test-configs/planetscale
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"connector": "vitess",
"version": "8.0",
"version": "planetscale.js",
"driver_adapter": "planetscale",
"driver_adapter_config": {
"proxy_url": "http://root:[email protected]:8085",
"connection_string_override": "mysql://[email protected]:3310/{database}"
"proxy_url": "http://root:[email protected]:8085"
},
"external_test_executor": "default"
}
4 changes: 3 additions & 1 deletion query-engine/connector-test-kit-rs/test-configs/sqlite
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
{
"connector": "sqlite"}
"connector": "sqlite",
"version": "3"
}

0 comments on commit bfe4811

Please sign in to comment.