Michael Schaufelberger
Michael Schaufelberger
Explore posts from servers
DTDrizzle Team
Created by jrydberg on 8/3/2024 in #help
How to get the type of transaction from a database?
export const db = drizzlePg(pool, {
schema,
});

export type DB = typeof db;
export type TX = Parameters<Parameters<DB['transaction']>[0]>[0];
export type DbOrTx = DB | TX;
export const db = drizzlePg(pool, {
schema,
});

export type DB = typeof db;
export type TX = Parameters<Parameters<DB['transaction']>[0]>[0];
export type DbOrTx = DB | TX;
is my solution to this. A function can use either DB, TX or DbOrTx as their prop/arg.
6 replies
DTDrizzle Team
Created by tzezar on 8/4/2024 in #help
Is using zod for type narrowing fine solution?
If you generally trust the data that's coming from your db, you can safely use e.g. type predicates to narrow the data further. This should usually be faster. But if you always have only a small dataset to check, use whatever gives the best DX imo.
2 replies
DTDrizzle Team
Created by nachliel on 2/25/2024 in #help
Updated drizzle-kit -> Error: Cannot find module 'drizzle-orm/pg-core'
Like besides installing it globally I mean
3 replies
DTDrizzle Team
Created by nachliel on 2/25/2024 in #help
Updated drizzle-kit -> Error: Cannot find module 'drizzle-orm/pg-core'
@nachliel Have you found a solution to this?
3 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
(zod/lib is 12 KB - so about 22 KB is drizzle-zod + -orm)
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
@lermatroid Sorry for hijacking this thread. It's a bummer, Discord doesn't allow threads in the Q&A chats.
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
Yeah, seems not to be an easy fix. Having said all that, I don't think it makes sense to create a schema only from the drizzle schema. createInsertSchema creates a schema to be used to validate DB inserts. This does not mean it's compatible to your API. Especially if you can create rather complex filters, etc. with GraphQL.
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
https://wundergraph.com/blog/a_comprehensive_guide_to_wundergraph#usequery it looks like Wundergraph already has some validation. Maybe zod is not even needed...?
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
Have you seen this? https://github.com/fabien0102/ts-to-zod#limitation Maybe you can adjust Wundergraph's output to match the limitations. Also, I suggest trying it on a small part of the file first and see if it works.
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
Oh, just noticed you're not OP. This reply is for you @diamond.dragon
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
Okay. So you want zod schemas for validation of graphql api calls? In that case, I think you are better off generating the zod schemas with a library from here https://zod.dev/?id=x-to-zod Based on your use case, I think ts-to-zod will fit. But there's also a GraphQL codegen one.
16 replies
DTDrizzle Team
Created by Liam on 7/18/2023 in #help
Importing drizzle-zod Schemas on the Client
Maybe someone has a better solution... but here it goes. Personally, I wouldn't do that because - It essentially means that the client will have to import all the drizzle-zod dependencies
- this includes drizzle and afaik your db schema. (Maybe that will be better once "use server" and "use client" are smarter?) - Bundle size increases for the client. - TypeScript performance decreases significantly - since it needs to infer both, zod and the db schema. After a small project with many entities, I found that drizzle-zod isn't that helpful to build client-side forms or API inputs with. Mainly, because of the reasons above and because I almost always had to refine every single field besides id or a createdAt anyway. (adding email, length or other constraints). So what I'm doing: Create an extra zod schema in e.g. entities/user/schema.ts ```ts const SOME_CONSTANT = "foo"; export const userSchema = z.object({...}); export type User = z.infer<typeof userSchema>; ``` Create a db schema in e.g. entities/user/table.ts ```ts // Can easily use SOME_CONSTANT export const usersTable = pgTable(...); // Add refinements/transformations for certain db fields. E.g. JSON fields. export const usersTableInsertSchema = createInsertSchema(usersTable); export type UsersTableInsert = z.infer<typeof usersTableInsertSchema>; ``` This way, client modules with e.g. react-hook-form code can simply import entities/user/schema.ts` without having the baggage of drizzle. The backend API handlers (I'm using tRPC) can import both. The schemas for the form/client and the db insert schema. This means you can still make transformations/parsing checks e.g. for JSON fields right before the insert - but without bothering the client with it. Let me know if that works for you.
16 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
And the error message doesn't mention amount. But stricter typing will easily be enough. Again: Sorry!
34 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
I'm so getting used to typesafety with this project (trpc, drizzle, zod).
34 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
I'm so so sorry
34 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
like in this second. i'm stupid and forgot to define the amount column 🤦‍♂️
34 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
i just found the issue
34 replies
DTDrizzle Team
Created by Michael Schaufelberger on 5/12/2023 in #help
MySQL (Planetscale): Cannot read properties of undefined (reading 'name')
const insert = values[0];
console.log('insert', insert);
try {
const sql = ctx.db.insert(ticketInvitations).values(insert).toSQL();
const insert = values[0];
console.log('insert', insert);
try {
const sql = ctx.db.insert(ticketInvitations).values(insert).toSQL();
same issue
insert {
guestId: 1,
ticketTypeId: '6458eeb763aee7ab82c8b79b',
eventId: 1,
amount: 1
}
TypeError: Cannot read properties of undefined (reading 'name')
insert {
guestId: 1,
ticketTypeId: '6458eeb763aee7ab82c8b79b',
eventId: 1,
amount: 1
}
TypeError: Cannot read properties of undefined (reading 'name')
34 replies