NazCodeland
Explore posts from serversTransaction response time
Hey everyone, in my code I have a
createUser(), createProfile(), createBusiness(), and createAddress()
for this example.
Currently, I have creaeUser()
execute on it's own and then the other 3 free functions execute as one transaction. Which gives me the benefit of having a fast response time for when a user creates an account. (the loading screen is quick) but I don't know if that benefit outweighs the risk of having user records in the database without a profile, business, and/or address
records - *if for some reason the transaction fails but the createUser()
executed fine.
I really like the fast signup user experience provided by just awaiting createUser()
without having to wait for a whole transaction to complete. Is there any way to handle this scenario other than optimizing the functions within the transaction as much as possible?49 replies
Making Transactions with KyselyAdapter for auth.js
Hey everyone, I am using this KyselyAdapter package for auth.js https://github.com/nextauthjs/next-auth/pull/5464
I made slight changes since I am in a SvetleKit project and it works!
This package returns and object of functions, each function creates, updates, deletes a record in the database.
I am not sure how I would go about using these functions to create a transaction. Prior to using this package, I wrote my own KyselyAdapter for auth.js but in ( for it wasn't working in some situation, so I switched ) but this is how I wrote a transaction using my own KyselyAdapter
I realize the purpose of https://github.com/nextauthjs/next-auth/pull/5464 is to be used with auth.js - and it serves that objective
But for me to write a transaction like the above code snippet, I would have to modify that packages code - which I don't want to do
14 replies
Best practice around building query functions
Hey, I've looked around the docs somewhat but still not confident if I should do this:
Say, I have a
createUser
function, and then I need access to that returned user object within createProfile
. I could also create a findUserById()
function like in the docs, and call findUserById()
within createProfile()
but then I would have to pass the userObject or user.id to createProfile(), which is fine, but before I start implementing it this way, I figure I should ask if this is the ideal way or is there a better way29 replies
Declaring types under 'kysely-codegen' module
Hey everyone, because I'm using Prisma to push schemas to my database (it's because my Zod Schemas) also getting generated from my Prisma schemas -- it's why I'm still using it incase you're wondering why I'm in this situation:
I have a
./types/kysely-codegen.d.ts
file which contains
in another file I have
BaseUser
gives me the error that 19 replies
From Prisma Model to Kysely Schema
Hey everyone, I'm using this package https://github.com/valtyr/prisma-kysely, the output of this Prisma Model is
so when I have Kysely code such as
8 replies
Triggers vs stored procedures
Hey everyone, I don't think this is related to Kysely directly, so excuse me but this is the only SQL type of server I am in. I am wondering what is the best way to automatically update a table attribute based on when another attribute changes (in the same table or another table). For example, if I want to have the attributes
updatedAt
and lastLogin
updated on their own from the Model below
I need these values determines automatically. I have some sources saying use Triggers and some saying just have functions that you can invoke yourself in server side logic.
Based on an article, this seems to be the main con of triggers
and the main pro seems to be that whereas, functions on the server have a chance of not running due to an errorr occuring right before the attributes updatedAt
, lastLogin
are updated14 replies
`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
39 replies