Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(js-connectors): DX, enable hooks for connect() and disconnect() #4177

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

13 changes: 13 additions & 0 deletions quaint/src/connector/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ pub trait Queryable: Send + Sync {
fn requires_isolation_first(&self) -> bool;
}

#[async_trait]
pub trait Connectable: Queryable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this trait be moved to js-connectors instead? I don't think quaint's connecteors implement that, JsConnector is the only one that needs it.

async fn connect(&self) -> crate::Result<()> {
Ok(())
}

async fn disconnect(&self) -> crate::Result<()> {
Ok(())
}
}

/// A thing that can start a new transaction.
#[async_trait]
pub trait TransactionCapable: Queryable {
Expand Down Expand Up @@ -128,3 +139,5 @@ macro_rules! impl_default_TransactionCapable {
}

pub(crate) use impl_default_TransactionCapable;

pub trait JsConnectorLike: TransactionCapable + Connectable {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, this looks out of place in quaint to me.

2 changes: 1 addition & 1 deletion quaint/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A "prelude" for users of the `quaint` crate.
pub use crate::ast::*;
pub use crate::connector::{
ConnectionInfo, DefaultTransaction, Queryable, ResultRow, ResultSet, SqlFamily, TransactionCapable,
Connectable, ConnectionInfo, DefaultTransaction, Queryable, ResultRow, ResultSet, SqlFamily, TransactionCapable,
};
pub use crate::{col, val, values};
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
5 changes: 5 additions & 0 deletions query-engine/connectors/query-connector/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ pub trait Connector {
/// Returns a connection to a data source.
async fn get_connection(&self) -> crate::Result<Box<dyn Connection + Send + Sync>>;

/// Disconnects from the data source.
async fn disconnect(&self) -> crate::Result<()> {
Ok(())
}

/// Returns the name of the connector.
fn name(&self) -> &'static str;

Expand Down
Loading
Loading