1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
import { sql as _sql } from 'drizzle-orm';
import type {
BooleanColumnInput,
ColumnsConfig,
DBConfigInput,
DateColumnInput,
JsonColumnInput,
NumberColumnOpts,
TableConfig,
TextColumnOpts,
} from '../core/types.js';
function createColumn<S extends string, T extends Record<string, unknown>>(type: S, schema: T) {
return {
type,
/**
* @internal
*/
schema,
};
}
export const column = {
number: <T extends NumberColumnOpts>(opts: T = {} as T) => {
return createColumn('number', opts) satisfies { type: 'number' };
},
boolean: <T extends BooleanColumnInput['schema']>(opts: T = {} as T) => {
return createColumn('boolean', opts) satisfies { type: 'boolean' };
},
text: <T extends TextColumnOpts>(opts: T = {} as T) => {
return createColumn('text', opts) satisfies { type: 'text' };
},
date<T extends DateColumnInput['schema']>(opts: T = {} as T) {
return createColumn('date', opts) satisfies { type: 'date' };
},
json<T extends JsonColumnInput['schema']>(opts: T = {} as T) {
return createColumn('json', opts) satisfies { type: 'json' };
},
};
export function defineTable<TColumns extends ColumnsConfig>(userConfig: TableConfig<TColumns>) {
return userConfig;
}
export function defineDb(userConfig: DBConfigInput) {
return userConfig;
}
// Exports a few common expressions
export const NOW = _sql`CURRENT_TIMESTAMP`;
export const TRUE = _sql`TRUE`;
export const FALSE = _sql`FALSE`;
export {
sql,
eq,
gt,
gte,
lt,
lte,
ne,
isNull,
isNotNull,
inArray,
notInArray,
exists,
notExists,
between,
notBetween,
like,
ilike,
notIlike,
not,
asc,
desc,
and,
or,
count,
countDistinct,
avg,
avgDistinct,
sum,
sumDistinct,
max,
min,
} from 'drizzle-orm';
export { alias } from 'drizzle-orm/sqlite-core';
export { isDbError } from './utils.js';
|