Skip to content

Commit

Permalink
feat(js-connectors): enable transaction levels (prisma#4107)
Browse files Browse the repository at this point in the history
* feat(js-connectors): enable transaction levels

* chore: fix clippy

* feat: update "rust-postgres" to prisma/rust-postgres@429e760

* chore: allow deprecated cuid

* chore: silence some deprecation warnings

* chore: allow deprecated cuid

* chore: silence some deprecation warnings

* chore: update Cargo.lock

* chore: fix deprecations on chrono

* Revert "chore: update Cargo.lock"

This reverts commit 6e376bc.

* chore: restore insta=1.21.1

* Revert "chore: silence some deprecation warnings"

This reverts commit a8b91ca.

* Revert "feat: update "rust-postgres" to prisma/rust-postgres@429e760"

This reverts commit 9369339.
  • Loading branch information
jkomyno authored Aug 14, 2023
1 parent 43696fa commit 4bac8fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions quaint/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct Error {
original_message: Option<String>,
}

pub(crate) struct ErrorBuilder {
pub struct ErrorBuilder {
kind: ErrorKind,
original_code: Option<String>,
original_message: Option<String>,
Expand All @@ -96,7 +96,7 @@ impl ErrorBuilder {
self
}

pub(crate) fn build(self) -> Error {
pub fn build(self) -> Error {
Error {
kind: self.kind,
original_code: self.original_code,
Expand All @@ -106,7 +106,7 @@ impl ErrorBuilder {
}

impl Error {
pub(crate) fn builder(kind: ErrorKind) -> ErrorBuilder {
pub fn builder(kind: ErrorKind) -> ErrorBuilder {
ErrorBuilder {
kind,
original_code: None,
Expand Down Expand Up @@ -298,7 +298,7 @@ impl ErrorKind {
}
}

pub(crate) fn invalid_isolation_level(isolation_level: &IsolationLevel) -> Self {
pub fn invalid_isolation_level(isolation_level: &IsolationLevel) -> Self {
Self::InvalidIsolationLevel(isolation_level.to_string())
}
}
Expand Down
16 changes: 14 additions & 2 deletions query-engine/js-connectors/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use napi::JsObject;
use psl::datamodel_connector::Flavour;
use quaint::{
connector::IsolationLevel,
error::{Error, ErrorKind},
prelude::{Query as QuaintQuery, Queryable as QuaintQueryable, ResultSet, TransactionCapable},
visitor::{self, Visitor},
Value,
Expand Down Expand Up @@ -131,13 +132,24 @@ impl QuaintQueryable for JsQueryable {

/// Sets the transaction isolation level to given value.
/// Implementers have to make sure that the passed isolation level is valid for the underlying database.
async fn set_tx_isolation_level(&self, _isolation_level: IsolationLevel) -> quaint::Result<()> {
async fn set_tx_isolation_level(&self, isolation_level: IsolationLevel) -> quaint::Result<()> {
if matches!(isolation_level, IsolationLevel::Snapshot) {
return Err(Error::builder(ErrorKind::invalid_isolation_level(&isolation_level)).build());
}

self.raw_cmd(&format!("SET TRANSACTION ISOLATION LEVEL {isolation_level}"))
.await?;

Ok(())
}

/// Signals if the isolation level SET needs to happen before or after the tx BEGIN.
fn requires_isolation_first(&self) -> bool {
false
match self.flavour {
Flavour::Mysql => true,
Flavour::Postgres | Flavour::Sqlite => false,
_ => unreachable!(),
}
}
}

Expand Down

0 comments on commit 4bac8fc

Please sign in to comment.