baronnoraz
baronnoraz
DTDrizzle Team
Created by chronark on 2/2/2024 in #help
"drizzle-orm/planetscale-serverless/migrator" in cf workers
I would love the ability to do something similar, run the migrate programmatically without having to do a generate and migrate. https://discord.com/channels/1043890932593987624/1202633333536718908
12 replies
DTDrizzle Team
Created by zej on 10/29/2023 in #help
FK identifier will be truncated... how to specify my own?
This works for me using MySQL and Drizzle...
export const userAccount = mysqlTable(
'user_account',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
userId: bigint('user_id', { mode: 'number' }).notNull(),
type: varchar('type', { length: 255 }).notNull(),
salt: varchar('salt', { length: 128 }).notNull(),
password: varchar('password', { length: 255 }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(ua) => {
return {
userIdIndex: index('ix_user_account_user_id').on(ua.userId),
typeIndex: index('ix_user_account_type').on(ua.type),
userIdTypeIndex: uniqueIndex('ux_user_account_user_id_type').on(ua.userId, ua.type),
userForeignKey: foreignKey({
columns: [ua.userId],
foreignColumns: [user.id],
name: 'fk_user_account_user_id'
})
};
},
);
export const userAccount = mysqlTable(
'user_account',
{
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement(),
userId: bigint('user_id', { mode: 'number' }).notNull(),
type: varchar('type', { length: 255 }).notNull(),
salt: varchar('salt', { length: 128 }).notNull(),
password: varchar('password', { length: 255 }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
},
(ua) => {
return {
userIdIndex: index('ix_user_account_user_id').on(ua.userId),
typeIndex: index('ix_user_account_type').on(ua.type),
userIdTypeIndex: uniqueIndex('ux_user_account_user_id_type').on(ua.userId, ua.type),
userForeignKey: foreignKey({
columns: [ua.userId],
foreignColumns: [user.id],
name: 'fk_user_account_user_id'
})
};
},
);
6 replies
DTDrizzle Team
Created by wheresthegold_ on 2/1/2024 in #help
Typing casting from JSON_OBJECT()
FWIW - I wouldn't expect/want that to behave differently. Since it's JSON, there's no way to know if {xyz: 0} should mean xyz = false or if it should be 0.
8 replies
DTDrizzle Team
Created by hdawg on 2/2/2024 in #help
How to end pool connections
I haven't used PostgreSQL with Drizzle yet, but I imagine it's something like...
const client = new Client(...);
await client.connect();
const db = drizzle(client);

// then in your afterAll or something...
client.end()
const client = new Client(...);
await client.connect();
const db = drizzle(client);

// then in your afterAll or something...
client.end()
At least that seems to be how the node-postgres driver has it, https://node-postgres.com/apis/client. But I may not be understanding what you're asking. I know Jest complains if I don't close the client connection in this way for MySQL.
4 replies
DTDrizzle Team
Created by rizaldiariif on 7/31/2023 in #help
Implementation of Drizzle and tsoa
I was curious if an issue ever got created, so that I could follow it. I am also lookin into how to update descriptions, but I'm having another problem to and was curious if @rizaldiariif had encountered it since they're using tsoa. When I do the following export type UserDbType = typeof user.$inferSelect then in a separate models packing in my monorepo, I do export type User = Pick<UserDbType, 'id', 'email'> tsoa generates my swagger documentation. But if I change the model to be export type User = UserDbType I get an error when generating the documentation that says
There was a problem resolving type of 'UserDbType'.
There was a problem resolving type of 'User'.
Generate swagger error.
GenerateMetadataError: Unknown type: TypeQuery
There was a problem resolving type of 'UserDbType'.
There was a problem resolving type of 'User'.
Generate swagger error.
GenerateMetadataError: Unknown type: TypeQuery
Have you ever had that problem? Actually my issue appears to be between TSOA and Zod, https://github.com/lukeautry/tsoa/issues/1256
5 replies
DTDrizzle Team
Created by baronnoraz on 12/29/2023 in #help
Unit Testing with Transactions
Thank you for that link as well!!
12 replies
DTDrizzle Team
Created by baronnoraz on 12/29/2023 in #help
Unit Testing with Transactions
@Angelelz that link is super helpful. Thank you! I appreciate the help and insight from everyone.
12 replies
DTDrizzle Team
Created by baronnoraz on 12/29/2023 in #help
Unit Testing with Transactions
We've only done this approach using in memory databases. I'd like to test against our MySQL or PostgreSQL databases directly. How do you go about standing up a db instance each time? I guess, how are you handling the "starting with a fresh DB every time". I'd love to see how others do this.
12 replies
DTDrizzle Team
Created by baronnoraz on 12/29/2023 in #help
Unit Testing with Transactions
sorry - I should have said integration test. I was looking at using something like jest-testcontainers to spin up a db instance in docker, then reset the db every time. We've just used this pattern a lot on other projects. It makes it a harder sell to use Drizzle ORM. Being able to access the transaction would be helpful in other was too, given how we have used Transaction Management in our service layer. Maybe it just feels wrong to not be able to access the transaction, especially when I've been in a world where we use save points and XA transactions. Simply seeing how others have approached the problem is extremely helpful.
12 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
I appreciate the help. I can't believe that I looked at that wrong. I knew that I had to be doing something dumb.
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
thanks - I'm a bone head.
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
dammit
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
but.... as I look at the deprecation - yep
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
Yeah, the examples show using InferModel but in my IDE it said that was deprecated to use InferModelType, it's from drizzle-orm version 0.29.1
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
Interesting. I saw that, but I was using (insert) export type UserModel = InferModelType<typeof user, 'insert'> and it wasn't working, but when I switched to the $inferInsert it works great. Was the InferModelType just wrong?
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
The problem is that the userSchema shows up as a type of MySQLTableWIthColumns... and not something simple like interface UserModel {id: number, ...}.
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
Right now, being able to give my frontend developers types/interfaces is the primary goal.
16 replies
DTDrizzle Team
Created by baronnoraz on 11/29/2023 in #help
create exportable types for frontend services
Both ideally, but I was speaking about types with my rest api to the frontend. I was also thinking that I could use drizzle-zod to validate - on the frontend and backend (when a request comes in), but I haven't gotten that far in my thinking.
16 replies