How to add multiple tables in a single export object

So for example I have these tables
export const orderssection = mysqlTable('orderssection', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});

export const orderssectiontwo = mysqlTable('orderssectiontwo', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});

export const orderssectionthree = mysqlTable('orderssectionthree', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});
export const orderssection = mysqlTable('orderssection', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});

export const orderssectiontwo = mysqlTable('orderssectiontwo', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});

export const orderssectionthree = mysqlTable('orderssectionthree', {
firstName: varchar('first_name', { length: 30 }).notNull(),
lastName: varchar('last_name', { length: 30 }).notNull(),
});
now I would like to have a single export object for these tables What I tried to do
const insertOrdersSectionThreeSchema = createInsertSchema(OrdersSectionThree)
const insertOrdersSectionTwoSchema = createInsertSchema(OrdersSectionTwo)
const insertOrdersSectionSchema = createInsertSchema(OrdersSection)

export const insertOrderSchema = insertOrdersSectionThreeSchema.and(insertOrdersSectionTwoSchema).and(insertOrdersSectionSchema)
const insertOrdersSectionThreeSchema = createInsertSchema(OrdersSectionThree)
const insertOrdersSectionTwoSchema = createInsertSchema(OrdersSectionTwo)
const insertOrdersSectionSchema = createInsertSchema(OrdersSection)

export const insertOrderSchema = insertOrdersSectionThreeSchema.and(insertOrdersSectionTwoSchema).and(insertOrdersSectionSchema)
now this export
insertOrderSchema
insertOrderSchema
has three tables inside it where i can insert data to them at once the issue is when using "and" in
insertOrdersSectionThreeSchema.and(insertOrdersSectionTwoSchema).and(insertOrdersSectionSchema)
insertOrdersSectionThreeSchema.and(insertOrdersSectionTwoSchema).and(insertOrdersSectionSchema)
it creates multiple zod intersections, so what is the best way to add multiple tables schema in a single export zodobject in drizzle.
1 Reply
Azzam
AzzamOP8mo ago
nvm using
.extend
.extend
works
Want results from more Discord servers?
Add your server