You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
393 B
12 lines
393 B
import { sql } from "drizzle-orm";
|
|
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
|
|
/** Drizzle SQLite 手动主键递增 */
|
|
export async function nextIntegerId(table: unknown, idColumn: unknown): Promise<number> {
|
|
const [row] = await dbGlobal
|
|
.select({
|
|
maxId: sql<number>`COALESCE(MAX(${idColumn as never}), 0)`,
|
|
})
|
|
.from(table as never);
|
|
return (row?.maxId ?? 0) + 1;
|
|
}
|
|
|