Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.76k stars 104 forks source link

The database queries are applied to shadow database instead of the main one. #255

Closed bangbaew closed 1 year ago

bangbaew commented 1 year ago

in schema.prisma, i have

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}

after successful migration, i have done several queries (find, create) and use a db admin to check the database tables, all the queries are made to the shadow database, not the main one, and when i manually try adding a row to a table in the main database, the find query didn't return anything from that database, it returns data from the shadow database.

I don't know why this is happening, but in prisma-client-go, the queries are applied to the main database url, not the shadow one.

Brendonovich commented 1 year ago

Hmm, it may be because of this

image

Switching the order around might do the job

Brendonovich commented 1 year ago

Can you try using rev = "4766d89b1a38fc57475582a095f803da2d330b34" instead of tag = "0.6.4"?

bangbaew commented 1 year ago

Can you try using rev = "4766d89b1a38fc57475582a095f803da2d330b34" instead of tag = "0.6.4"?

This one is working as expected, thank you. But I have another concern, I want to import the struct from the generated struct Data

pub mod some_table...
#[derive(Debug, Clone, :: serde :: Serialize, :: serde :: Deserialize)]
    pub struct Data {
        #[serde(rename = "id")]
        pub id: String,
        #[serde(rename = "created_at")]
        pub created_at:
            ::prisma_client_rust::chrono::DateTime<::prisma_client_rust::chrono::FixedOffset>,
        #[serde(rename = "updated_at")]
        pub updated_at:
            ::prisma_client_rust::chrono::DateTime<::prisma_client_rust::chrono::FixedOffset>,
        #[serde(rename = "name")]
        pub name: String,
        #[serde(rename = "chant")]
        pub chant: Option<Vec<super::chant::Data>>,
    }

this one is from the generated prisma.rs, which has already implemented the data models, I just wanna import this and use with a web framework (Actix) for a POST request body like this web::Json<Data>, so I won't have to write a new struct again, but when I send a request with JSON post body {"name": "some_string"} it responded Json deserialize error: missing fieldidat line 3 column 1 because I didn't specify the rest of the fields (id, created_at, updated_at) which should not be required as it's autogenerated by Prisma client. Is there any way I can import and ignore the deserialization for those fields?

Or can you add #[serde(skip_serializing)] to the autogenerated fields as well as make the nullable fields can be ignored, like SetIfPresent in go client prisma?

Thanks.

Brendonovich commented 1 year ago

That use case isn't supported, you'll need to create another struct to use as your input. Data structs are just database result types, nothing more.