P
Prisma•7d ago
dxkyy

Can I access a database, which was created with prisma, with a normal sql driver?

I can connect to my database using sqlx in rust and fetch data, but when I try to insert data I'm getting an error
Created: Err(Database(PgDatabaseError { severity: Error, code: "42601", message: "syntax error at or near \"#\"", detail: None, hint: None, position: Some(Original(55)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("scan.l"), line: Some(1244), routine: Some("scanner_yyerror") }))
Created: Err(Database(PgDatabaseError { severity: Error, code: "42601", message: "syntax error at or near \"#\"", detail: None, hint: None, position: Some(Original(55)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("scan.l"), line: Some(1244), routine: Some("scanner_yyerror") }))
My schema looks like this:
model Artist {
external_urls Json
href String
id String @id
name String
type String
uri String
Track Track? @relation(fields: [trackId], references: [id])
trackId String?
Album Album? @relation(fields: [albumId], references: [id])
albumId String?
}
model Artist {
external_urls Json
href String
id String @id
name String
type String
uri String
Track Track? @relation(fields: [trackId], references: [id])
trackId String?
Album Album? @relation(fields: [albumId], references: [id])
albumId String?
}
5 Replies
Nurul
Nurul•7d ago
Hey @dxkyy 👋
Can I access a database, which was created with prisma
When you say the database was created by Prisma, do you mean you were using Prisma Postgres? https://www.prisma.io/postgres
Prisma
Prisma Postgres | Instant Global Databases
Free to start, no setup, no commitments. Easily grow your database as your app scales.
dxkyy
dxkyyOP•7d ago
Oh, no i created it using the prisma client in a typescript project but i also need to access the same database in a rust project, and prisma-client-rust is not an option for me
Nurul
Nurul•7d ago
Ah, okay! Ideally yes, you should be able to connect to the database with other sql driver. If I understand correctly, while using the database in rust project - you are able to query data but not insert data?
dxkyy
dxkyyOP•7d ago
yes, exactly this is the code thats causing problems:
let artist_exists = sqlx::query("SELECT * FROM \"Artist\" WHERE id = $1").bind(artist.id.clone()).fetch_one(pool).await;
match artist_exists {
Ok(_) => {
info!("Artist exists: {}", artist.name);
info!("Database: {:?}", artist_exists);
}
Err(_) => {
info!("Artist does not exist: {}", artist.name);
let created = sqlx::query("INSERT INTO \"Artist\" (external_urls, href, id, name, r#type, uri) VALUES ($1, $2, $3, $4, $5, $6) RETURNING name").bind(artist.external_urls.clone()).bind(artist.href.clone()).bind(artist.id.clone()).bind(artist.name.clone()).bind(artist.r#type.clone()).bind(artist.uri.clone()).execute(pool).await;
info!("Created: {:?}", created);
}
}
let artist_exists = sqlx::query("SELECT * FROM \"Artist\" WHERE id = $1").bind(artist.id.clone()).fetch_one(pool).await;
match artist_exists {
Ok(_) => {
info!("Artist exists: {}", artist.name);
info!("Database: {:?}", artist_exists);
}
Err(_) => {
info!("Artist does not exist: {}", artist.name);
let created = sqlx::query("INSERT INTO \"Artist\" (external_urls, href, id, name, r#type, uri) VALUES ($1, $2, $3, $4, $5, $6) RETURNING name").bind(artist.external_urls.clone()).bind(artist.href.clone()).bind(artist.id.clone()).bind(artist.name.clone()).bind(artist.r#type.clone()).bind(artist.uri.clone()).execute(pool).await;
info!("Created: {:?}", created);
}
}
i think it has something to do with the relations, how do I fix that?
Nurul
Nurul•7d ago
I am not sure if this is a prisma related issue. I haven't used sqlx so I am not sure how to fix this. Does a normal insert without relations work?
Want results from more Discord servers?
Add your server