Skip to content

Commit

Permalink
Merge pull request #423 from Brendonovich/scalar-type-aliases
Browse files Browse the repository at this point in the history
Scalar type aliases
  • Loading branch information
Brendonovich committed Dec 29, 2023
2 parents b1d3f6e + 28cec59 commit ad188e5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
3 changes: 3 additions & 0 deletions crates/generator/src/lib.rs
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/mod.rs
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
2 changes: 2 additions & 0 deletions crates/generator/src/read_filters.rs
Expand Up @@ -73,6 +73,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
Expand Up @@ -84,6 +84,8 @@ pub fn generate_module(args: &GenerateArgs) -> TokenStream {

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

#(#write_params)*
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/lib/src/lib.rs
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 Down
9 changes: 9 additions & 0 deletions crates/lib/src/scalar_types.rs
@@ -0,0 +1,9 @@
pub type Int = i32;
pub type BigInt = i64;
pub type Decimal = bigdecimal::BigDecimal;
pub type Boolean = bool;
pub type DateTime = chrono::DateTime<chrono::FixedOffset>;
pub type Float = f64;
pub type String = std::string::String;
pub type Json = serde_json::Value;
pub type Bytes = Vec<u8>;
20 changes: 2 additions & 18 deletions crates/sdk/src/extensions.rs
Expand Up @@ -225,25 +225,9 @@ pub trait ScalarTypeExt {

impl ScalarTypeExt for ScalarType {
fn to_tokens(&self) -> TokenStream {
let pcr = quote!(::prisma_client_rust);
let ident = format_ident!("{}", self.as_str());

match self {
ScalarType::Int => quote!(i32),
ScalarType::BigInt => quote!(i64),
ScalarType::Float => quote!(f64),
ScalarType::Decimal => quote!(#pcr::bigdecimal::BigDecimal),
ScalarType::Boolean => quote!(bool),
ScalarType::String => quote!(String),
ScalarType::Json => quote!(#pcr::serde_json::Value),
ScalarType::DateTime => {
quote!(
#pcr::chrono::DateTime<
#pcr::chrono::FixedOffset,
>
)
}
ScalarType::Bytes => quote!(Vec<u8>),
}
quote!(#ident)
}

fn to_prisma_value(&self, var: &Ident) -> TokenStream {
Expand Down

1 comment on commit ad188e5

@vercel
Copy link

@vercel vercel bot commented on ad188e5 Dec 29, 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.