Skip to content

Commit

Permalink
Merge pull request #422 from Brendonovich/417-unique-array-error
Browse files Browse the repository at this point in the history
fix arrays in unique where param
  • Loading branch information
Brendonovich committed Dec 28, 2023
2 parents deb32b9 + 6b77d2f commit b1d3f6e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

17 changes: 12 additions & 5 deletions crates/generator/src/models/where_params.rs
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 @@ -644,9 +651,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: #field_type) -> T {
Equals(value).into()
}
Expand All @@ -657,12 +664,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: #field_type) -> T {
Equals(value).into()
}
Expand Down
2 changes: 2 additions & 0 deletions tests/issues/issue-417/.cargo/config.toml
@@ -0,0 +1,2 @@
[alias]
prisma = "run -p prisma-cli --features postgresql --"
10 changes: 10 additions & 0 deletions tests/issues/issue-417/Cargo.toml
@@ -0,0 +1,10 @@
[package]
name = "issue-417"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
prisma-client-rust = { workspace = true, features = ["postgresql", "migrations"], default-features = false }
serde.workspace = true
18 changes: 18 additions & 0 deletions tests/issues/issue-417/prisma/schema.prisma
@@ -0,0 +1,18 @@
datasource db {
provider = "postgresql"
url = "postgres://postgres:postgrespw@localhost:55000"
}

generator client {
provider = "cargo prisma"
output = "../src/db"
// necessary since the generated file won't be at crate::prisma
module_path = "db"
client_format = "folder"
}

model Item {
numericId BigInt @unique @default(autoincrement())
path BigInt[] @unique
}
12 changes: 12 additions & 0 deletions tests/issues/issue-417/src/lib.rs
@@ -0,0 +1,12 @@
#[allow(warnings, unused)]
mod db;

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test() {
let _: db::item::WhereParam = db::item::path::equals(vec![0, 1, 2, 3]);
}
}

1 comment on commit b1d3f6e

@vercel
Copy link

@vercel vercel bot commented on b1d3f6e Dec 28, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.