Files
payload/packages/drizzle/src/queries/operatorMap.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

59 lines
922 B
TypeScript

import {
type Column,
type SQL,
type SQLWrapper,
and,
eq,
gt,
gte,
ilike,
inArray,
isNotNull,
isNull,
lt,
lte,
ne,
notInArray,
or,
} from 'drizzle-orm'
type OperatorKeys =
| 'and'
| 'contains'
| 'equals'
| 'exists'
| 'greater_than'
| 'greater_than_equal'
| 'in'
| 'isNull'
| 'less_than'
| 'less_than_equal'
| 'like'
| 'not_equals'
| 'not_in'
| 'or'
export type Operators = Record<OperatorKeys, (column: Column, value: SQLWrapper | unknown) => SQL>
export const operatorMap: Operators = {
and,
contains: ilike,
equals: eq,
exists: isNotNull,
greater_than: gt,
greater_than_equal: gte,
in: inArray,
isNull, // handles exists: false
less_than: lt,
less_than_equal: lte,
like: ilike,
not_equals: ne,
// TODO: geojson queries
// intersects: intersects,
// near: near,
// within: within,
// all: all,
not_in: notInArray,
or,
}