Does Drizzle-Orm Expose Wrapper Types?

So I want to write a wrapper around drizzle-orm where I can pass in things like a where filter or order filter so in case I ever change to a different ORM I can do so. Does drizzle-orm expose the types for each of these methods? Or is there some example of folks writing a general wrapper around it? For example, type-orm exposes a lot of input option types like below:
import {
FindManyOptions,
FindOneOptions,
FindOperator,
FindOptionsSelect,
FindOptionsWhere,
OrderByCondition
} from "typeorm";

import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder";
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations";
import {
FindManyOptions,
FindOneOptions,
FindOperator,
FindOptionsSelect,
FindOptionsWhere,
OrderByCondition
} from "typeorm";

import { FindOptionsOrder } from "typeorm/find-options/FindOptionsOrder";
import { FindOptionsRelations } from "typeorm/find-options/FindOptionsRelations";
3 Replies
Angelelz
Angelelz12mo ago
The input for findMany and findFirst is very dependent on your schema, tables and relations. We were discussing how to provide an easy to use helper type but there are other priorities and the results we were getting weren't that good Take a look at this discussion where I offered some workarounds
Angelelz
Angelelz12mo ago
GitHub
Relations input · drizzle-team drizzle-orm · Discussion #1483
I have a schema that looks like somewhat like this: export const employeesSchema = pgTable('employees', { firstName: varchar('first_name', { length: 256 }), lastName: varchar('l...
Paul
PaulOP12mo ago
Thank you. And if I just want to provide some additional options like filtering, orderBy, where options around my wrapper get method, are there any examples for this by any chance? async getEmailById(data: string, options: any): Promise<void> { await client.select().from(emails).where(eq(emails.id, data)); } I got something like the code below from AI, but wondering how to define the difference argument types - Predicate, Order, SelectedFields
import { eq, asc } from 'drizzle-orm';

async function getFilteredEmailData(
whereClause?: Predicate | Predicate[],
orderByClause?: Order | Order[],
filterFields?: SelectedFields<emails>,
): Promise<void> {
let query = client.select(filterFields).from(emails);

if (whereClause) {
query = query.where(whereClause);
}

if (orderByClause) {
query = query.orderBy(orderByClause);
}

await query;
}
import { eq, asc } from 'drizzle-orm';

async function getFilteredEmailData(
whereClause?: Predicate | Predicate[],
orderByClause?: Order | Order[],
filterFields?: SelectedFields<emails>,
): Promise<void> {
let query = client.select(filterFields).from(emails);

if (whereClause) {
query = query.where(whereClause);
}

if (orderByClause) {
query = query.orderBy(orderByClause);
}

await query;
}
Want results from more Discord servers?
Add your server