`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
I am using Prisma schema to define my schema so since I don't have a kysely file where I am defining my interfaces(schemas), I think I need to import the interface from
node_modules/kysely-codegen/dist/db.d.ts
and setup the Selectable, Insertable, Updatable
in there
or, I define them inside of my Kysely.ts file where I have the connection info/Kysely db instance
that's a silly question, I'll try defining them inside of kysely.ts and if that works i'll use that otherwise try the kysely.d.ts
thanks again! I'll close thisits probably safer to define these extras in your src folder instead and commit.
my kysely.ts file is inside of
/src/database/kysely/kysely.ts
whereas the kysely.d.ts
file is located at the root /types/kysely.d.ts
but I could move that /types
folder inside of src so it get's committed (if that's what you mean by commit) to the repoyeah
🙏