PgTable type how to get at least have id field?
i want to make common crud service in nest js how to set PgTable type to have id field?
import { Inject, Injectable } from '@nestjs/common';
import { PgInsertValue, PgTable } from 'drizzle-orm/pg-core';
import { DB, DBType } from './drizzle.provider';
import { eq } from 'drizzle-orm';
@Injectable()
export class DrizzleService<T extends PgTable> {
constructor(
@Inject(DB) private readonly db: DBType,
private readonly table: T,
) { }
async create(
input: PgInsertValue<T>,
): Promise<typeof this.table.$inferSelect> {
const [res] = await this.db.insert(this.table).values(input).returning();
return res;
}
async update(id: number, input: Partial<PgInsertValue<T>>) {
const [res] = await this.db
.update(this.table)
.set(input)
.where(eq(this.table.id, id))
.returning();
}
}
import { Inject, Injectable } from '@nestjs/common';
import { PgInsertValue, PgTable } from 'drizzle-orm/pg-core';
import { DB, DBType } from './drizzle.provider';
import { eq } from 'drizzle-orm';
@Injectable()
export class DrizzleService<T extends PgTable> {
constructor(
@Inject(DB) private readonly db: DBType,
private readonly table: T,
) { }
async create(
input: PgInsertValue<T>,
): Promise<typeof this.table.$inferSelect> {
const [res] = await this.db.insert(this.table).values(input).returning();
return res;
}
async update(id: number, input: Partial<PgInsertValue<T>>) {
const [res] = await this.db
.update(this.table)
.set(input)
.where(eq(this.table.id, id))
.returning();
}
}
1 Reply
i need to check type is have id field