Error types with custom schema

Hi, I'm trying to do a general function to paginate my querys, but I'm having some problems with the types.
I'm trying to use the types of the library, but I'm not sure if I'm doing it right.
All my tables have the same columns, so I created a function to create the base table, and I'm trying to use it to create the pagination function,
and definitly i'm doing it wrong but I'm not shure how to do it, could you point me in the right direction? to know if it's possible to do it.

const baseMysqlTable = <TColumnsMap extends Record<string, AnyMySqlColumnBuilder>>(name: string, columns: TColumnsMap) => {
    return mysqlTable(name, {
        ...columns,
        id: int('id').primaryKey().autoincrement().notNull(),
        updatedAt: timestamp('updated_at').onUpdateNow(),
        createdAt: timestamp('created_at').defaultNow(),
        deletedAt: timestamp('deleted_at')
    });
};

type BaseMysqlTable = InferModel<typeof baseMysqlTable>;

const withPagination = async <S extends AnyMySqlSelect, T extends BaseMysqlTable>(qb: S, table: T, offset = 0, limit = 10) => {
    const data = await qb.offset(offset).limit(limit).orderBy(desc(table.id));
    // const count = await db.select(sql<number>`count(${table.id})`).from(table);
    return {
        data,
        offset,
        limit,
        // total: count[0]
    }
}
Was this page helpful?