Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich authored Dec 13, 2024
2 parents a1c0759 + 64bd7cf commit 6de9c6c
Show file tree
Hide file tree
Showing 61 changed files with 9,159 additions and 3,131 deletions.
4,890 changes: 3,048 additions & 1,842 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[workspace]
members = [
"examples/*",
"examples/tauri/src-tauri",
"integration-tests",
"tests/*/*",
"crates/*",
"crates/sdk/example/*",
"prisma-cli"
"examples/*",
"examples/tauri/src-tauri",
"integration-tests",
"tests/*/*",
"crates/*",
"crates/sdk/example/*",
"prisma-cli",
]
exclude = ["examples/tauri"]
resolver = "2"
Expand All @@ -27,7 +27,11 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

convert_case = "0.6.0"
rspc = { version = "=1.0.0-rc.5" }

specta = { version = "=2.0.0-rc.1" }
tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta", branch = "v2" }
tauri-specta = { version = "2.0.0-rc.9" }

# This is a deprecated feature so we don't really care about the verison
rspc = "*"

# We don't lock version cause PCR only depends on `derive(Type)` so it should be fine.
specta = "^2.0.0-rc"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<h1>Prisma Client Rust</h1>
<p><b>Type-safe database access for Rust</b></p>
<img src="https://img.shields.io/badge/latest-0.6.10-blue?style=flat-square" alt="Latest version of Prisma Client Rust is 0.6.10">
<img src="https://img.shields.io/badge/latest-0.6.11-blue?style=flat-square" alt="Latest version of Prisma Client Rust is 0.6.11">
<a href="https://prisma.io">
<img src="https://img.shields.io/static/v1?label=prisma&message=v4.8.0&color=blue&logo=prisma&style=flat-square" alt="Latest supported Prisma version is 4.8.0">
</a>
Expand Down
5 changes: 4 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ proc-macro2 = "1.0.39"
http = "0.2.6"
directories = "4.0.1"
flate2 = "1.0.23"
reqwest = { version = "0.11.10", features = ["blocking"] }
reqwest = { version = "0.11.10", features = [
"blocking",
"native-tls-vendored",
] }
regex = "1.5.5"
thiserror = "1.0.37"

Expand Down
36 changes: 19 additions & 17 deletions crates/cli/src/binaries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use directories::BaseDirs;
use flate2::read::GzDecoder;
use http::StatusCode;
use reqwest::blocking as reqwest;
use std::fs::{copy, create_dir_all, metadata, File};
use std::fs::{rename, create_dir_all, metadata, File, remove_file};
use std::io;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -123,26 +123,28 @@ fn download(url: String, to: String) -> Result<(), ()> {
panic!("received code {} from {}", resp.status(), &url);
};

let mut tmp_file = File::create(tmp).expect(&format!("could not create {}", tmp));
{
let mut tmp_file = File::create(tmp).expect(&format!("could not create {}", tmp));

if !cfg!(target_os = "windows") {
Command::new("chmod")
.arg("+x")
.arg(tmp)
.output()
.expect("failed to make file executable");
}
if !cfg!(target_os = "windows") {
Command::new("chmod")
.arg("+x")
.arg(tmp)
.output()
.expect("failed to make file executable");
}

let mut buffer = Vec::new();
io::BufReader::new(GzDecoder::new(resp))
.read_to_end(&mut buffer)
.unwrap();
let mut buffer = Vec::new();
io::BufReader::new(GzDecoder::new(resp))
.read_to_end(&mut buffer)
.unwrap();

tmp_file
.write(buffer.as_slice())
.expect("could not write to .tmp file");
tmp_file
.write(buffer.as_slice())
.expect("could not write to .tmp file");

copy(tmp, to).expect(&format!("could not copy file {}", url));
}
rename(tmp, to).expect(&format!("could not rename file {}", url));

Ok(())
}
2 changes: 1 addition & 1 deletion crates/cli/src/binaries/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn parse_openssl_version(v: &str) -> String {
let matches = r.unwrap().captures(v).unwrap();
if matches.len() > 0 {
match matches.get(1).unwrap().as_str() {
"3.1" => "3.0.x".to_string(),
version if version.starts_with("3.") => "3.0.x".to_string(),
version => format!("{version}.x"),
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions crates/generator-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ edition = "2021"
[lib]
proc-macro = true

[features]
specta = []

[dependencies]
prisma-client-rust-generator-shared = { path = "../generator-shared" }
convert_case.workspace = true
proc-macro2 = "1.0.39"
quote = "1.0.18"
syn = "1.0.91"

specta = { workspace = true, optional = true }
2 changes: 1 addition & 1 deletion crates/generator-macros/src/partial_unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn proc_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let specta_attrs = cfg!(feature = "specta").then(|| {
quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(crate = "prisma_client_rust::specta")]
#[specta(crate = prisma_client_rust::specta)]
}
});

Expand Down
15 changes: 8 additions & 7 deletions crates/generator-macros/src/select_include/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn definitions(input: &Input) -> TokenStream {
if cfg!(feature = "specta") {
attrs.extend(quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(crate = "prisma_client_rust::specta")]
#[specta(crate = prisma_client_rust::specta)]
});

attrs.extend(match &macro_rules.name {
Expand Down Expand Up @@ -62,9 +62,10 @@ pub fn definitions(input: &Input) -> TokenStream {
let (field_type, field_module) = field_in_selectables
.zip(field_in_selection.and_then(|f| f.sub_selection.as_ref()))
.and_then(|(field_in_selectables, (variant, sub_selection))| {
let Arity::Relation(relation_model_path, arity) = &field_in_selectables.arity else {
return None;
};
let Arity::Relation(relation_model_path, arity) = &field_in_selectables.arity
else {
return None;
};

let value = quote! {
pub mod #ident {
Expand All @@ -77,9 +78,9 @@ pub fn definitions(input: &Input) -> TokenStream {
let base = quote!(#ident::Data);

let typ = match arity {
RelationArity::One => base,
RelationArity::Many => quote!(Vec<#base>),
RelationArity::Optional => quote!(Option<#base>),
RelationArity::One => base,
RelationArity::Many => quote!(Vec<#base>),
RelationArity::Optional => quote!(Option<#base>),
};

Some((typ, Some(value)))
Expand Down
5 changes: 4 additions & 1 deletion crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ proc-macro2 = "1.0.39"
http = "0.2.6"
directories = "4.0.1"
flate2 = "1.0.23"
reqwest = { version = "0.11.10", features = ["blocking"] }
reqwest = { version = "0.11.10", features = [
"blocking",
"native-tls-vendored",
] }
regex = "1.5.5"
thiserror = "1.0.37"

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/composite_types/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn struct_definition(ty: CompositeTypeWalker) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #ty_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #ty_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn generate(args: &GenerateArgs) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #model_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #model_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
3 changes: 3 additions & 0 deletions crates/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl PrismaGenerator for Generator {
#header

pub use _prisma::*;
use prisma_client_rust::scalar_types::*;

#enums
},
Expand All @@ -65,6 +66,8 @@ impl PrismaGenerator for Generator {
module.add_submodule(Module::new(
"_prisma",
quote! {
use super::*;

#client
#internal_enums
#read_filters_module
Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/models/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn r#struct(model: ModelWalker) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #model_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #model_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn modules(args: &GenerateArgs, module_path: &TokenStream) -> Vec<Module> {
let mut module = Module::new(
model.name(),
quote! {
use super::_prisma::*;
use super::{_prisma::*, *};

pub const NAME: &str = #model_name;

Expand Down
17 changes: 12 additions & 5 deletions crates/generator/src/models/where_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ impl Variant {
field_name: field.name().to_string(),
field_required_type: field
.scalar_field_type()
.to_tokens(module_path, &FieldArity::Required, field.db)
.to_tokens(
module_path,
&match field.ast_field().arity {
FieldArity::Optional => FieldArity::Required,
a => a,
},
field.db,
)
.unwrap(),
read_filter_name: read_filter.name.to_string(),
optional: field.ast_field().arity.is_optional(),
Expand Down Expand Up @@ -645,9 +652,9 @@ pub fn field_module(
let mut fields = idx.fields();
idx.is_unique() && fields.len() == 1 && fields.next().map(|f| f.field_id()) == Some(scalar_field.field_id())
}),
arity.is_required()
arity.is_optional()
) {
(true, _, _) | (_, true, true) => quote! {
(true, _, _) | (_, true, false) => quote! {
pub fn equals<T: From<Equals>>(value: impl Into<#field_type>) -> T {
Equals(value.into()).into()
}
Expand All @@ -658,12 +665,12 @@ pub fn field_module(
}
}
},
(_, true, false) => quote! {
(_, true, true) => quote! {
pub fn equals<T: #pcr::FromOptionalUniqueArg<Equals>>(value: T::Arg) -> T {
T::from_arg(value)
}
},
(_, _, _) => quote! {
(false, false, _) => quote! {
pub fn equals<T: From<Equals>>(value: impl Into<#field_type>) -> T {
Equals(value.into()).into()
}
Expand Down
15 changes: 8 additions & 7 deletions crates/generator/src/read_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {

let typ = field.type_tokens(&quote!(super::super::));

// https://github.com/Brendonovich/prisma-client-rust/issues/297
if filter.name == "JsonNullable" && field.name == "equals" {
Some((
match (filter.name.as_str(), field.name.as_str()) {
// https://github.com/Brendonovich/prisma-client-rust/issues/297
("JsonNullable", "equals") => Some((
quote!(#variant_name(Option<#typ>)),
quote! {
Self::#variant_name(#value_ident) =>
Expand All @@ -37,9 +37,8 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {
)]
)
},
))
} else {
Some((
)),
_ => Some((
quote!(#variant_name(#typ)),
quote! {
Self::#variant_name(#value_ident) =>
Expand All @@ -50,7 +49,7 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {
)]
)
},
))
)),
}
})
.unzip();
Expand All @@ -73,6 +72,8 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {

quote! {
pub mod read_filters {
use super::*;

#(#read_filters)*
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/generator/src/write_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {

quote! {
pub mod write_params {
use super::*;

#(#write_params)*
}
}
Expand Down
11 changes: 9 additions & 2 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ default = []
rspc = ["dep:rspc", "specta"]
specta = ["dep:specta", "prisma-client-rust-generator-macros/specta"]
sqlite-create-many = ["psl/sqlite-create-many"]
migrations = ["schema-core", "dep:include_dir", "dep:tempfile", "tokio/fs", "dep:tracing"]
migrations = [
"schema-core",
"dep:include_dir",
"dep:tempfile",
"tokio/fs",
"dep:tracing",
]
mocking = ["tokio"]
# mutation-callbacks = []

Expand All @@ -27,7 +33,8 @@ serde.workspace = true
serde_json.workspace = true
chrono = { version = "0.4.19", features = ["serde"] }
thiserror = "1.0.30"
bigdecimal = { version = "0.3", features = ["serde"] }
bigdecimal = { version = "0.4", features = ["serde"] }
bigdecimal_03 = { package = "bigdecimal", version = "0.3" }
uuid = { version = "1", features = ["serde"] }
indexmap = "1.8.2"
serde-value = "0.7.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl PrismaClientInternals {
Ok(url) => Some(url),
Err(_) => source.load_shadow_database_url()?,
}
.unwrap();
.expect("Datasource could not be fetched, please check your schema.prisma file or your environment variables");

match url.starts_with("file:") {
true => {
Expand Down
4 changes: 3 additions & 1 deletion crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod operator;
mod prisma_value;
pub mod queries;
pub mod raw;
pub mod scalar_types;
pub mod serde;
mod traits;
mod transaction;
Expand All @@ -26,7 +27,8 @@ use std::collections::HashMap;

pub use bigdecimal;
pub use chrono;
pub use prisma_models::{self, PrismaValue};
pub use prisma_models;
pub use prisma_value::PrismaValue;
pub use psl;
pub use query_core;
pub use query_core::{schema, Selection};
Expand Down
Loading

0 comments on commit 6de9c6c

Please sign in to comment.