`Selectable`, `Insertable` and `Updateable` wrappers
Hey everyone, I am using this package: https://github.com/valtyr/prisma-kysely and I noticed that the output file does not include
for the tables that I have in my schema, I don't know if that's not required because of my setup or if that is still required, I opened an issue in the repo but figured I ask here too
21 Replies
Those types are not required in any sense. They can be handy in function input types and such. You can create them yourself if the type generator doesn't do that. Nothing in Kysely "reads" the typing file in any way. All kysely knows about the types is what you pass the Kysely class as type arguments.
@bonsaye Thanks for opening the issue in
prisma-kysely
, that could be of use to many users actually.I've switched from using prisma-kysely package to using the Kysely-codegen package, but I still use Prisma models to push my schema to the database (mainly because I want to generate Zod schemas from the Prisma models. However, is it not possible for me to use
now that I am using Kysely-codegen, if I am not using Kysely interfaces to define my schema?
Feel like I am misunderstanding something
Its a common mistake we've seen in issues and discord, that users would use
Database['person']
as the type returned from a select query.
so this part tells you to use the helpers around Database['person']
to extract the proper type based on use casedamn man, sorry for being a nuisance just wanna understand. I really don't get this part.
for example,
No problem
first, does it mean that Selectable defines a table type that is only selectable and not editable?
people would use
PetTable
as the return type of a method that does some select query.
instead of Selectable<PetTable>
Generated<T>
is ColumnType<SelectType = T, InsertType | null, UpdateType | null>
iircare you able to show me what you mean by
`people would use PetTable as return type
based on this example
or
sorry but if you want you can use the example in the docs associated with that step. If that's easierSelectable
for example, takes PetTable
and turns it from
to
ah
so you can use that as a type?
yeah, if you're being explicit about return types
what is the difference betwen the Selectable ( I see what it does ) what about Insertable/Updateable - also are these the only 3 of their kind?
ColumnType
has 3 generic slots, one for select type, one for insert type and one for update type
Selectable
extracts the select type
Insertable
extracts the insert type
Updateable
extracts the update typebeautiful, now I get it and which one to use when making Kysely queries
thank you very much Igal
before I let you go xD
wanna show you one thing