Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/openssl-0.10.60
Browse files Browse the repository at this point in the history
  • Loading branch information
janpio committed Dec 7, 2023
2 parents 9a05382 + 12d71c4 commit a66c0b4
Show file tree
Hide file tree
Showing 97 changed files with 2,752 additions and 352 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export SIMPLE_TEST_MODE="yes" # Reduces the amount of generated `relation_link_t
### QE specific logging vars ###
export QE_LOG_LEVEL=debug # Set it to "trace" to enable query-graph debugging logs
# export PRISMA_RENDER_DOT_FILE=1 # Uncomment to enable rendering a dot file of the Query Graph from an executed query.
# export FMT_SQL=1 # Uncomment it to enable logging formatted SQL queries
export FMT_SQL=1 # Uncomment it to enable logging formatted SQL queries

### Uncomment to run driver adapters tests. See query-engine-driver-adapters.yml workflow for how tests run in CI.
# export EXTERNAL_TEST_EXECUTOR="napi"
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/send-tag-event.yml

This file was deleted.

1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions libs/prisma-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ impl PrismaValue {
_ => None,
}
}

pub fn as_json(&self) -> Option<&String> {
if let Self::Json(v) = self {
Some(v)
} else {
None
}
}
}

impl fmt::Display for PrismaValue {
Expand Down
2 changes: 1 addition & 1 deletion nix/all-engines.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
src = srcPath;
name = "prisma-engines-source";
};
craneLib = (flakeInputs.crane.mkLib pkgs).overrideToolchain rustToolchain.default;
craneLib = (flakeInputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
deps = craneLib.vendorCargoDeps { inherit src; };
libSuffix = stdenv.hostPlatform.extensions.sharedLibrary;
in
Expand Down
4 changes: 3 additions & 1 deletion nix/args.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
in rec
{
pkgs = import flakeInputs.nixpkgs { inherit system overlays; };
rustToolchain = pkgs.rust-bin.stable.latest;
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = ["wasm32-unknown-unknown"];
};
};
}
12 changes: 9 additions & 3 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
{ self', pkgs, rustToolchain, ... }:

let
devToolchain = rustToolchain.default.override { extensions = [ "rust-analyzer" "rust-src" ]; };
devToolchain = rustToolchain.override { extensions = [ "rust-analyzer" "rust-src" ]; };
nodejs = pkgs.nodejs_latest;
in
{
devShells.default = pkgs.mkShell {
packages = [
packages = with pkgs; [
devToolchain
pkgs.llvmPackages_latest.bintools
llvmPackages_latest.bintools

nodejs
nodejs.pkgs.typescript-language-server
nodejs.pkgs.pnpm

jq
graphviz
wasm-bindgen-cli
wasm-pack
];

inputsFrom = [ self'.packages.prisma-engines ];
shellHook = pkgs.lib.optionalString pkgs.stdenv.isLinux
"export RUSTFLAGS='-C link-arg=-fuse-ld=lld'";
Expand Down
3 changes: 2 additions & 1 deletion psl/builtin-connectors/src/cockroach_datamodel_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Connector
FilteredInlineChildNestedToOneDisconnect |
InsertReturning |
UpdateReturning |
RowIn
RowIn |
LateralJoin
});

const SCALAR_TYPE_DEFAULTS: &[(ScalarType, CockroachType)] = &[
Expand Down
4 changes: 3 additions & 1 deletion psl/builtin-connectors/src/postgres_datamodel_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Connector
NativeUpsert |
InsertReturning |
UpdateReturning |
RowIn
RowIn |
DistinctOn |
LateralJoin
});

pub struct PostgresDatamodelConnector;
Expand Down
8 changes: 6 additions & 2 deletions psl/psl-core/src/common/preview_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ macro_rules! features {
};
}

// (Usually) Append-only list of features.
// (Usually) Append-only list of features. (alphabetically sorted)
features!(
AggregateApi,
AtomicNumberOperations,
Expand Down Expand Up @@ -64,6 +64,7 @@ features!(
MultiSchema,
NamedConstraints,
NApi,
NativeDistinct,
NativeTypes,
OrderByAggregateGroup,
OrderByNulls,
Expand All @@ -76,9 +77,10 @@ features!(
TransactionApi,
UncheckedScalarInputs,
Views,
RelationJoins
);

/// Generator preview features
/// Generator preview features (alphabetically sorted)
pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
active: enumflags2::make_bitflags!(PreviewFeature::{
Deno
Expand All @@ -87,9 +89,11 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
| FullTextSearch
| Metrics
| MultiSchema
| NativeDistinct
| PostgresqlExtensions
| Tracing
| Views
| RelationJoins
}),
deprecated: enumflags2::make_bitflags!(PreviewFeature::{
AtomicNumberOperations
Expand Down
4 changes: 3 additions & 1 deletion psl/psl-core/src/datamodel_connector/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ capabilities!(
NativeUpsert,
InsertReturning,
UpdateReturning,
RowIn, // Connector supports (a, b) IN (c, d) expression.
RowIn, // Connector supports (a, b) IN (c, d) expression.
DistinctOn, // Connector supports DB-level distinct (e.g. postgres)
LateralJoin,
);

/// Contains all capabilities that the connector is able to serve.
Expand Down
2 changes: 1 addition & 1 deletion psl/psl/tests/config/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn nice_error_for_unknown_generator_preview_feature() {
.unwrap_err();

let expectation = expect![[r#"
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, postgresqlExtensions, tracing, views[0m
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins[0m
--> schema.prisma:3
 | 
 2 |  provider = "prisma-client-js"
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use ordering::{IntoOrderDefinition, Order, OrderDefinition, Orderable, Order
pub use over::*;
pub use query::{Query, SelectQuery};
pub use row::Row;
pub use select::Select;
pub use select::{DistinctType, Select};
pub use table::*;
pub use union::Union;
pub use update::*;
Expand Down
10 changes: 9 additions & 1 deletion quaint/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ mod average;
mod coalesce;
mod concat;
mod count;
mod json_array_agg;
mod json_build_obj;
#[cfg(any(feature = "postgresql", feature = "mysql"))]
mod json_extract;
#[cfg(any(feature = "postgresql", feature = "mysql"))]
Expand All @@ -28,6 +30,8 @@ pub use average::*;
pub use coalesce::*;
pub use concat::*;
pub use count::*;
pub use json_array_agg::*;
pub use json_build_obj::*;
#[cfg(any(feature = "postgresql", feature = "mysql"))]
pub use json_extract::*;
#[cfg(any(feature = "postgresql", feature = "mysql"))]
Expand Down Expand Up @@ -98,6 +102,8 @@ pub(crate) enum FunctionType<'a> {
JsonExtractFirstArrayElem(JsonExtractFirstArrayElem<'a>),
#[cfg(any(feature = "postgresql", feature = "mysql"))]
JsonUnquote(JsonUnquote<'a>),
JsonArrayAgg(JsonArrayAgg<'a>),
JsonBuildObject(JsonBuildObject<'a>),
#[cfg(any(feature = "postgresql", feature = "mysql"))]
TextSearch(TextSearch<'a>),
#[cfg(any(feature = "postgresql", feature = "mysql"))]
Expand Down Expand Up @@ -154,5 +160,7 @@ function!(
Minimum,
Maximum,
Coalesce,
Concat
Concat,
JsonArrayAgg,
JsonBuildObject
);
18 changes: 18 additions & 0 deletions quaint/src/ast/function/json_array_agg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::prelude::*;

#[derive(Debug, Clone, PartialEq)]
pub struct JsonArrayAgg<'a> {
pub(crate) expr: Box<Expression<'a>>,
}

/// Builds a JSON array out of a list of values.
pub fn json_array_agg<'a, E>(expr: E) -> Function<'a>
where
E: Into<Expression<'a>>,
{
let fun = JsonArrayAgg {
expr: Box::new(expr.into()),
};

fun.into()
}
15 changes: 15 additions & 0 deletions quaint/src/ast/function/json_build_obj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use std::borrow::Cow;

use crate::prelude::*;

#[derive(Debug, Clone, PartialEq)]
pub struct JsonBuildObject<'a> {
pub(crate) exprs: Vec<(Cow<'a, str>, Expression<'a>)>,
}

/// Builds a JSON object out of a list of key-value pairs.
pub fn json_build_object<'a>(exprs: Vec<(Cow<'a, str>, Expression<'a>)>) -> Function<'a> {
let fun = JsonBuildObject { exprs };

fun.into()
}
9 changes: 9 additions & 0 deletions quaint/src/ast/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ast::{ConditionTree, Table};
pub struct JoinData<'a> {
pub(crate) table: Table<'a>,
pub(crate) conditions: ConditionTree<'a>,
pub(crate) lateral: bool,
}

impl<'a> JoinData<'a> {
Expand All @@ -13,8 +14,14 @@ impl<'a> JoinData<'a> {
Self {
table: table.into(),
conditions: ConditionTree::NoCondition,
lateral: false,
}
}

pub fn lateral(mut self) -> Self {
self.lateral = true;
self
}
}

impl<'a, T> From<T> for JoinData<'a>
Expand Down Expand Up @@ -73,6 +80,7 @@ where
JoinData {
table: self.into(),
conditions: conditions.into(),
lateral: false,
}
}
}
Expand All @@ -90,6 +98,7 @@ impl<'a> Joinable<'a> for JoinData<'a> {
JoinData {
table: self.table,
conditions,
lateral: false,
}
}
}
24 changes: 22 additions & 2 deletions quaint/src/ast/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::borrow::Cow;
/// A builder for a `SELECT` statement.
#[derive(Debug, PartialEq, Clone, Default)]
pub struct Select<'a> {
pub(crate) distinct: bool,
pub(crate) distinct: Option<DistinctType<'a>>,
pub(crate) tables: Vec<Table<'a>>,
pub(crate) columns: Vec<Expression<'a>>,
pub(crate) conditions: Option<ConditionTree<'a>>,
Expand All @@ -18,6 +18,12 @@ pub struct Select<'a> {
pub(crate) comment: Option<Cow<'a, str>>,
}

#[derive(Debug, PartialEq, Clone)]
pub enum DistinctType<'a> {
Default,
OnClause(Vec<Expression<'a>>),
}

impl<'a> From<Select<'a>> for Expression<'a> {
fn from(sel: Select<'a>) -> Expression<'a> {
Expression {
Expand Down Expand Up @@ -236,7 +242,12 @@ impl<'a> Select<'a> {
/// # }
/// ```
pub fn distinct(mut self) -> Self {
self.distinct = true;
self.distinct = Some(DistinctType::Default);
self
}

pub fn distinct_on(mut self, columns: Vec<Expression<'a>>) -> Self {
self.distinct = Some(DistinctType::OnClause(columns));
self
}

Expand Down Expand Up @@ -391,6 +402,15 @@ impl<'a> Select<'a> {
self
}

pub fn left_join_lateral<J>(self, join: J) -> Self
where
J: Into<JoinData<'a>>,
{
let join_data: JoinData = join.into();

self.left_join(join_data.lateral())
}

/// Adds `RIGHT JOIN` clause to the query.
///
/// ```rust
Expand Down
9 changes: 9 additions & 0 deletions quaint/src/ast/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ impl<'a> Table<'a> {
self
}

pub fn left_join_lateral<J>(self, join: J) -> Self
where
J: Into<JoinData<'a>>,
{
let join_data: JoinData = join.into();

self.left_join(join_data.lateral())
}

/// Adds an `INNER JOIN` clause to the query, specifically for that table.
/// Useful to positionally add a JOIN clause in case you are selecting from multiple tables.
///
Expand Down
Loading

0 comments on commit a66c0b4

Please sign in to comment.