Skip to content

Commit

Permalink
use Uuid::from_str instead of Uuid::from_slice (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich authored Aug 20, 2023
1 parent f53484c commit d4ee744
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 12 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

9 changes: 0 additions & 9 deletions crates/generator/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,5 @@ pub fn generate(args: &GenerateArgs) -> TokenStream {
static DATABASE_STR: &'static str = #database_string;

#migrations_include

pub async fn new_client() -> Result<PrismaClient, #pcr::NewClientError> {
PrismaClient::_builder().build().await
}

// adapted from https://github.com/polytope-labs/prisma-client-rs/blob/0dec2a67081e78b42700f6a62f414236438f84be/codegen/src/prisma.rs.template#L182
pub async fn new_client_with_url(url: &str) -> Result<PrismaClient, #pcr::NewClientError> {
PrismaClient::_builder().with_url(url.to_string()).build().await
}
}
}
4 changes: 1 addition & 3 deletions crates/lib/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ impl From<RawTypedJson> for RawPrismaValue {
}
("json", v) => RawPrismaValue::Json(v),
("xml", String(s)) => RawPrismaValue::Xml(s),
("uuid", String(s)) => {
RawPrismaValue::Uuid(uuid::Uuid::from_slice(s.as_bytes()).unwrap())
}
("uuid", String(s)) => RawPrismaValue::Uuid(uuid::Uuid::from_str(&s).unwrap()),
("datetime", String(s)) => {
RawPrismaValue::DateTime(chrono::DateTime::parse_from_rfc3339(&s).unwrap().into())
}
Expand Down
1 change: 1 addition & 0 deletions prisma-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
sqlite = ["prisma-client-rust-cli/sqlite", "prisma-client-rust-cli/sqlite-create-many"]
mongodb = ["prisma-client-rust-cli/mongodb"]
postgresql = ["prisma-client-rust-cli/postgresql"]
mssql = ["prisma-client-rust-cli/mssql"]
specta = ["prisma-client-rust-cli/specta"]
mocking = ["prisma-client-rust-cli/mocking"]

Expand Down
2 changes: 2 additions & 0 deletions tests/database/sqlserver/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
prisma = "run -p prisma-cli --features mssql --"
25 changes: 25 additions & 0 deletions tests/database/sqlserver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "sqlserver-tests"
version = "0.1.0"
edition = "2021"

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

[[test]]
name = "integration_tests"
path = "tests/lib.rs"
harness = true

[dependencies]
prisma-client-rust = { workspace = true, features = [
"mssql",
"migrations",
] }
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
tokio = { version = "1.17.0", features = ["rt", "macros"] }
prisma-client-rust = { workspace = true, features = [
"mssql",
"migrations",
] }
Empty file.
16 changes: 16 additions & 0 deletions tests/database/sqlserver/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

generator client {
provider = "cargo prisma"
output = "../tests/db"
module_path = "crate::db"
client_format = "folder"
}

model TestTable {
id String @id @default(uuid()) @db.UniqueIdentifier
}
19 changes: 19 additions & 0 deletions tests/database/sqlserver/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use prisma_client_rust::raw;

use crate::db::{test_table, PrismaClient};

#[allow(warnings)]
mod db;

#[tokio::test]
async fn issue_378() -> Result<(), Box<dyn std::error::Error>> {
let client = PrismaClient::_builder().build().await?;

client.test_table().create(vec![]).exec().await?;
let _: Vec<test_table::Data> = client
._query_raw(raw!("SELECT id FROM TestTable"))
.exec()
.await?;

Ok(())
}

1 comment on commit d4ee744

@vercel
Copy link

@vercel vercel bot commented on d4ee744 Aug 20, 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.