K
Kysely2y ago
Nil

i am trying to select my id from type uuid

when i select all id from administrator table, it returns me status 200 and returns all id
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.execute()
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.execute()
but when i try to select a single id, it returns me status 400 badrequest
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.where("id", "=", "a0ac162b-9f03-44f3-b3b1-a0b31538e10c")
.execute()
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.where("id", "=", "a0ac162b-9f03-44f3-b3b1-a0b31538e10c")
.execute()
what am i doing wrong?
1 Reply
koskimas
koskimas2y ago
There's nothing wrong with the query itself. I think you have a bug in your logic somewhere else. If your data type is UUID then you might need to do something like this
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.where("id", "=", asUuid("a0ac162b-9f03-44f3-b3b1-a0b31538e10c"))
.execute()

function asUuid(uuid: string) {
return sql<string>`${uuid}::uuid`
}
const responseDb = await db
.withSchema("schemaName")
.selectFrom("administrator")
.select("id")
.where("id", "=", asUuid("a0ac162b-9f03-44f3-b3b1-a0b31538e10c"))
.execute()

function asUuid(uuid: string) {
return sql<string>`${uuid}::uuid`
}
I'd suggest avoiding the uuid datatype unless you really really really need to save disk space. Kysely doesn't return/use any kind of HTTP or other status codes. Those come from the framework you're using.
Want results from more Discord servers?
Add your server