Files
payload/packages/db-sqlite/src/schema/getIDColumn.ts
Dan Ribbens 09ad6e4280 feat(drizzle): abstract shared sql code to new package (#7320)
- Abstract shared sql code to a new drizzle package
- Adds sqlite package, not ready to publish until drizzle patches some
issues
- Add `transactionOptions` to allow customizing or disabling db
transactions
- Adds "experimental" label to the `schemaName` property until drizzle
patches an issue
2024-07-24 12:43:29 -04:00

39 lines
588 B
TypeScript

import { integer, numeric, text } from 'drizzle-orm/sqlite-core'
import type { IDType } from '../types.js'
export const getIDColumn = ({
name,
type,
notNull,
primaryKey,
}: {
name: string
notNull?: boolean
primaryKey: boolean
type: IDType
}) => {
let column
switch (type) {
case 'integer':
column = integer(name)
break
case 'numeric':
column = numeric(name)
break
case 'text':
column = text(name)
break
}
if (notNull) {
column.notNull()
}
if (primaryKey) {
column.primaryKey()
}
return column
}