Multi dialect CRUD lib

Hi 👋 I am attempting to develop a multi-dialect CRUD library that enables the execution of CRUD operations for various databases, including PostgreSQL, SQLite, MySQL, and others. However, unfortunately, drizzle-ORM is structured in a manner that prevents me from implementing even a basic prototype that includes a create method that supports all databases and ensures complete type accuracy. Could any team member assist me in initiating this project? Here's my minimal prototype:
import type { Table, } from 'drizzle-orm'
import type { PgDatabase } from 'drizzle-orm/pg-core'
import type { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'

type AnyDatabase = PgDatabase<any> | BaseSQLiteDatabase<any, any>

class BaseCrud<T extends Table> {
constructor(
private readonly db: AnyDatabase,
private readonly table: T,
) {
this.db = db
this.table = table
}

async create(data: T['$inferInsert'] | T['$inferInsert'][]): Promise<T['$inferSelect']> {
const result = await this.db.insert(this.table).values(data).returning()

return Array.isArray(data) ? result : result[0]
}
}

export { BaseCrud }
import type { Table, } from 'drizzle-orm'
import type { PgDatabase } from 'drizzle-orm/pg-core'
import type { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core'

type AnyDatabase = PgDatabase<any> | BaseSQLiteDatabase<any, any>

class BaseCrud<T extends Table> {
constructor(
private readonly db: AnyDatabase,
private readonly table: T,
) {
this.db = db
this.table = table
}

async create(data: T['$inferInsert'] | T['$inferInsert'][]): Promise<T['$inferSelect']> {
const result = await this.db.insert(this.table).values(data).returning()

return Array.isArray(data) ? result : result[0]
}
}

export { BaseCrud }
Getting error at .insert
This expression is not callable.
Each member of the union type '(<TTable extends PgTable>(table: TTable) => PgInsertBuilder<TTable, any, false>) | (<TTable extends SQLiteTable>(into: TTable) => SQLiteInsertBuilder<TTable, any, any>)' has signatures, but none of those signatures are compatible with each other.
This expression is not callable.
Each member of the union type '(<TTable extends PgTable>(table: TTable) => PgInsertBuilder<TTable, any, false>) | (<TTable extends SQLiteTable>(into: TTable) => SQLiteInsertBuilder<TTable, any, any>)' has signatures, but none of those signatures are compatible with each other.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?