// Types from https://github.com/drizzle-team/drizzle-orm/issues/695
type Schema = typeof primarySchemas;
type TSchema = ExtractTablesWithRelations<Schema>;
export type IncludeRelation<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>['with'];
export type InferResultType<
TableName extends keyof TSchema,
With extends IncludeRelation<TableName> | undefined = undefined,
> = BuildQueryResult<
TSchema,
TSchema[TableName],
{
with: With;
}
>;
async paginatedQuery<
U extends keyof drizzleOrm.ExtractTablesWithRelations<typeof schema>,
TableRelations extends IncludeRelation<U>,
>(
table: BaseTable,
{
with: queryWith,
}: {
with: TableRelations;
},
) {
const tableName = this.getTableName(table);
const data: Array<InferResultType<U, typeof queryWith>> =
await this.db.query[tableName].findMany({
with: queryWith
});
return { data, meta };
}
// Types from https://github.com/drizzle-team/drizzle-orm/issues/695
type Schema = typeof primarySchemas;
type TSchema = ExtractTablesWithRelations<Schema>;
export type IncludeRelation<TableName extends keyof TSchema> = DBQueryConfig<
'one' | 'many',
boolean,
TSchema,
TSchema[TableName]
>['with'];
export type InferResultType<
TableName extends keyof TSchema,
With extends IncludeRelation<TableName> | undefined = undefined,
> = BuildQueryResult<
TSchema,
TSchema[TableName],
{
with: With;
}
>;
async paginatedQuery<
U extends keyof drizzleOrm.ExtractTablesWithRelations<typeof schema>,
TableRelations extends IncludeRelation<U>,
>(
table: BaseTable,
{
with: queryWith,
}: {
with: TableRelations;
},
) {
const tableName = this.getTableName(table);
const data: Array<InferResultType<U, typeof queryWith>> =
await this.db.query[tableName].findMany({
with: queryWith
});
return { data, meta };
}