Skip to content

Commit

Permalink
feat(js-connectors): use standard provider names ("mysql", "postgres"…
Browse files Browse the repository at this point in the history
…, ...) (#4141)

* feat(js-connectors): use "standard" provider names ("mysql", "postgres", ...) with JS connectors

* chore(js-connectors): remove deprecated unit tests

* chore(js-connectors): remove "@prisma/pg" from smoke tests

* chore(query-engine): move ConnectorMode from psl to request_handlers

* chore(query-engine): remove deprecated tests
  • Loading branch information
jkomyno committed Aug 29, 2023
1 parent 08cc777 commit c021fae
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 266 deletions.
19 changes: 1 addition & 18 deletions psl/builtin-connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ pub use mongodb::MongoDbType;
pub use mssql_datamodel_connector::{MsSqlType, MsSqlTypeParameter};
pub use mysql_datamodel_connector::MySqlType;
pub use postgres_datamodel_connector::{PostgresDatasourceProperties, PostgresType};
pub use psl_core::js_connector::JsConnector;

mod mongodb;
mod mssql_datamodel_connector;
mod mysql_datamodel_connector;
mod native_type_definition;
mod neon;
mod pg_js;
mod planetscale;
mod postgres_datamodel_connector;
mod sqlite_datamodel_connector;

Expand All @@ -29,18 +25,5 @@ pub const MYSQL: &'static dyn Connector = &mysql_datamodel_connector::MySqlDatam
pub const SQLITE: &'static dyn Connector = &sqlite_datamodel_connector::SqliteDatamodelConnector;
pub const MSSQL: &'static dyn Connector = &mssql_datamodel_connector::MsSqlDatamodelConnector;
pub const MONGODB: &'static dyn Connector = &mongodb::MongoDbDatamodelConnector;
pub static PLANETSCALE_SERVERLESS: &'static dyn Connector = &planetscale::PLANETSCALE_SERVERLESS;
pub static NEON_SERVERLESS: &'static dyn Connector = &neon::NEON_SERVERLESS;
pub static PG_JS: &'static dyn Connector = &pg_js::PG_JS;

pub static BUILTIN_CONNECTORS: ConnectorRegistry = &[
POSTGRES,
MYSQL,
SQLITE,
MSSQL,
COCKROACH,
PG_JS,
MONGODB,
PLANETSCALE_SERVERLESS,
NEON_SERVERLESS,
];
pub static BUILTIN_CONNECTORS: ConnectorRegistry = &[POSTGRES, MYSQL, SQLITE, MSSQL, COCKROACH, MONGODB];
11 changes: 0 additions & 11 deletions psl/builtin-connectors/src/neon.rs

This file was deleted.

11 changes: 0 additions & 11 deletions psl/builtin-connectors/src/pg_js.rs

This file was deleted.

11 changes: 0 additions & 11 deletions psl/builtin-connectors/src/planetscale.rs

This file was deleted.

11 changes: 2 additions & 9 deletions psl/psl-core/src/datamodel_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ pub use self::{
relation_mode::RelationMode,
};

use crate::{
configuration::DatasourceConnectorData, js_connector::JsConnector, Configuration, Datasource, PreviewFeature,
};
use crate::{configuration::DatasourceConnectorData, Configuration, Datasource, PreviewFeature};
use diagnostics::{DatamodelError, Diagnostics, NativeTypeErrorFactory, Span};
use enumflags2::BitFlags;
use lsp_types::CompletionList;
Expand All @@ -44,11 +42,6 @@ pub const EXTENSIONS_KEY: &str = "extensions";

/// The datamodel connector API.
pub trait Connector: Send + Sync {
// Provides safe downcasting to a JsConnector, in case it is one.
fn as_js_connector(&self) -> Option<JsConnector> {
None
}

/// The name of the provider, for string comparisons determining which connector we are on.
fn provider_name(&self) -> &'static str;

Expand Down Expand Up @@ -368,7 +361,7 @@ pub trait Connector: Send + Sync {
}
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Flavour {
Cockroach,
Mongo,
Expand Down
125 changes: 0 additions & 125 deletions psl/psl-core/src/js_connector.rs

This file was deleted.

1 change: 0 additions & 1 deletion psl/psl-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![allow(clippy::derive_partial_eq_without_eq)]

pub mod datamodel_connector;
pub mod js_connector;

/// `mcf`: Turns a collection of `configuration::Datasource` and `configuration::Generator` into a
/// JSON representation. This is the `get_config()` representation.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use query_core::{
};
use query_engine_metrics::MetricRegistry;
use request_handlers::{
load_executor, BatchTransactionOption, GraphqlBody, JsonBatchQuery, JsonBody, JsonSingleQuery, MultiQuery,
RequestBody, RequestHandler,
load_executor, BatchTransactionOption, ConnectorMode, GraphqlBody, JsonBatchQuery, JsonBody, JsonSingleQuery,
MultiQuery, RequestBody, RequestHandler,
};
use std::{env, sync::Arc};

Expand Down Expand Up @@ -52,7 +52,15 @@ impl Runner {
let schema = psl::parse_schema(datamodel).unwrap();
let data_source = schema.configuration.datasources.first().unwrap();
let url = data_source.load_url(|key| env::var(key).ok()).unwrap();
let executor = load_executor(data_source, schema.configuration.preview_features(), &url).await?;

let connector_mode = ConnectorMode::Rust;
let executor = load_executor(
connector_mode,
data_source,
schema.configuration.preview_features(),
&url,
)
.await?;
let query_schema: QuerySchemaRef = Arc::new(schema::build(Arc::new(schema), true));

Ok(Self {
Expand Down
28 changes: 9 additions & 19 deletions query-engine/connectors/sql-query-connector/src/database/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub struct Js {
connector: JsConnector,
connection_info: ConnectionInfo,
features: psl::PreviewFeatures,
psl_connector: psl::builtin_connectors::JsConnector,
}

fn get_connection_info(url: &str) -> connector::Result<ConnectionInfo> {
Expand All @@ -70,23 +69,14 @@ impl FromSource for Js {
url: &str,
features: psl::PreviewFeatures,
) -> connector_interface::Result<Js> {
match source.active_connector.as_js_connector() {
Some(psl_connector) => {
let connector = registered_js_connector(source.active_provider)?;
let connection_info = get_connection_info(url)?;

Ok(Js {
connector,
connection_info,
features,
psl_connector,
})
}
None => panic!(
"Connector for provider {} is not a JsConnector",
source.active_connector.provider_name()
),
}
let connector = registered_js_connector(source.active_provider)?;
let connection_info = get_connection_info(url)?;

Ok(Js {
connector,
connection_info,
features,
})
}
}

Expand All @@ -101,7 +91,7 @@ impl Connector for Js {
}

fn name(&self) -> &'static str {
self.psl_connector.name
"js"
}

fn should_retry_on_transient_error(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ generator client {
}

datasource db {
provider = "@prisma/planetscale"
provider = "mysql"
url = env("JS_PLANETSCALE_DATABASE_URL")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ generator client {
}

datasource db {
provider = "@prisma/neon"
provider = "postgres"
url = env("JS_NEON_DATABASE_URL")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ generator client {
}

datasource db {
provider = "@prisma/pg"
provider = "postgres"
url = env("JS_PG_DATABASE_URL")
}

Expand Down
2 changes: 1 addition & 1 deletion query-engine/js-connectors/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use tracing::{info_span, Instrument};
///
pub struct JsBaseQueryable {
pub(crate) proxy: CommonProxy,
pub(crate) flavour: Flavour,
pub flavour: Flavour,
}

impl JsBaseQueryable {
Expand Down

0 comments on commit c021fae

Please sign in to comment.