daniel
daniel
DTDrizzle Team
Created by Liam on 7/8/2023 in #help
Drizzle-zod Include Relations
Sorry for slow reply. My approach is similar to @Liam 's mentioned above, I've just written a generic function that utilises z.object() and createInsertSchema() based upon iterating (recursively) the Drizzle relations structures. I will share the code when I can but been swamped recently.
10 replies
DTDrizzle Team
Created by Liam on 7/8/2023 in #help
Drizzle-zod Include Relations
Sure, though need to clean up slightly. I have some OpenAPI DTO annotation mixed in and it was a fiddle to get all going together.
10 replies
DTDrizzle Team
Created by Liam on 7/8/2023 in #help
Drizzle-zod Include Relations
I have a function which uses drizzle-zod then traverses the drizzle relations and uses zod's merge() function to expand the zod schema.
10 replies
DTDrizzle Team
Created by daniel on 6/11/2023 in #help
InferModel including relations?
@Andrew Sherman @Dan Kochetov Related question: Is there an official way to get the relation metadata? I'm currently doing the following:
import { createTableRelationsHelpers, extractTablesRelationalConfig, Table } from 'drizzle-orm';

/// Drizzle relations metadata
export const { tables: t } = extractTablesRelationalConfig(
s,
createTableRelationsHelpers,
);
import { createTableRelationsHelpers, extractTablesRelationalConfig, Table } from 'drizzle-orm';

/// Drizzle relations metadata
export const { tables: t } = extractTablesRelationalConfig(
s,
createTableRelationsHelpers,
);
16 replies
DTDrizzle Team
Created by daniel on 6/11/2023 in #help
InferModel including relations?
👍🏻 I've also used this mechanism in places.
16 replies
DTDrizzle Team
Created by daniel on 6/11/2023 in #help
InferModel including relations?
@gerty1 @chronicstone Sorry for the slow response! Similar to @intelligently 's answer:
export type TypeIncludingWith = Awaited<ReturnType<MyController['getItems']>>;
class MyController {
public async getItems() {
const rows = await this.db.query.inventoryItems.findMany({
with: {
designInfo: true,
},
where: ...
offset: offset,
limit: limit,
});
return rows;
}
}
export type TypeIncludingWith = Awaited<ReturnType<MyController['getItems']>>;
class MyController {
public async getItems() {
const rows = await this.db.query.inventoryItems.findMany({
with: {
designInfo: true,
},
where: ...
offset: offset,
limit: limit,
});
return rows;
}
}
16 replies
DTDrizzle Team
Created by Liam on 7/8/2023 in #help
Drizzle-zod Include Relations
So far, I do not think so. I have added them manually myself.
10 replies
DTDrizzle Team
Created by daniel on 5/29/2023 in #help
What versions of MySQL are supported? I have JSON_ARRAYAGG issues with 5.7 and AWS Aurora Serverless
@yordiv Just a note that I've patched drizzle to replace JSON_ARRAYAGG with concat and group_concat to get it wotking with my version of 5.7. This may be helpful for you.
4 replies