@revojs/storage 0.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, type AppendToNullabilityMap, type AppendToSelection, type Definition, type SelectMode, type Session, type Sql } from "../index";
2
+ export type TimestampMode = "date" | "string";
3
+ export interface CharOptions {
4
+ length?: number;
5
+ }
6
+ export interface DateOptions<TMode = TimestampMode> {
7
+ mode?: TMode;
8
+ }
9
+ export interface DecimalOptions {
10
+ precision: number;
11
+ scale: number;
12
+ }
13
+ export interface NumericOptions {
14
+ precision: number;
15
+ scale: number;
16
+ }
17
+ export interface TimestampOptions<TMode = TimestampMode> {
18
+ mode?: TMode;
19
+ precision?: number;
20
+ }
21
+ export interface VarcharOptions {
22
+ length?: number;
23
+ }
24
+ export declare abstract class PostgresqlColumn<TDataType = unknown> extends Column<TDataType> {
25
+ generatedAlwaysAsIdentity<This extends PostgresqlColumn>(this: This): This & Record<"generatedAlwaysAsIdentity", never>;
26
+ type<TData>(): this & Record<"$type", TData>;
27
+ }
28
+ export declare class BigintColumn extends PostgresqlColumn<bigint> {
29
+ toSqlType(): string;
30
+ }
31
+ export declare class BigserialColumn extends PostgresqlColumn<number> {
32
+ toSqlType(): string;
33
+ }
34
+ export declare class BooleanColumn extends PostgresqlColumn<boolean> {
35
+ toSqlType(): string;
36
+ }
37
+ export declare class CharColumn extends PostgresqlColumn<string> {
38
+ protected $options: CharOptions | undefined;
39
+ constructor(name: string, options?: CharOptions);
40
+ toSqlType(): string;
41
+ }
42
+ export declare class CidrColumn extends PostgresqlColumn<string> {
43
+ toSqlType(): string;
44
+ }
45
+ export declare class DateColumn extends PostgresqlColumn<Date> {
46
+ protected $options: DateOptions | undefined;
47
+ constructor(name: string, options?: DateOptions);
48
+ toSqlType(): string;
49
+ }
50
+ export declare class DecimalColumn extends PostgresqlColumn<string> {
51
+ protected $options: DecimalOptions | undefined;
52
+ constructor(name: string, options?: DecimalOptions);
53
+ toSqlType(): string;
54
+ }
55
+ export declare class DoublePrecisionColumn extends PostgresqlColumn<number> {
56
+ toSqlType(): string;
57
+ }
58
+ export declare class InetColumn extends PostgresqlColumn<string> {
59
+ toSqlType(): string;
60
+ }
61
+ export declare class IntegerColumn extends PostgresqlColumn<number> {
62
+ toSqlType(): string;
63
+ }
64
+ export declare class IntervalColumn extends PostgresqlColumn<string> {
65
+ toSqlType(): string;
66
+ }
67
+ export declare class JsonColumn extends PostgresqlColumn {
68
+ toSqlType(): string;
69
+ }
70
+ export declare class JsonbColumn extends PostgresqlColumn {
71
+ toSqlType(): string;
72
+ }
73
+ export declare class LineColumn extends PostgresqlColumn {
74
+ toSqlType(): string;
75
+ }
76
+ export declare class MacaddrColumn extends PostgresqlColumn<string> {
77
+ toSqlType(): string;
78
+ }
79
+ export declare class Macaddr8Column extends PostgresqlColumn<string> {
80
+ toSqlType(): string;
81
+ }
82
+ export declare class NumericColumn extends PostgresqlColumn<string> {
83
+ protected $options: NumericOptions | undefined;
84
+ constructor(name: string, options?: NumericOptions);
85
+ toSqlType(): string;
86
+ }
87
+ export declare class EnumerationColumn extends PostgresqlColumn<string> {
88
+ toSqlType(): string;
89
+ }
90
+ export declare class PointColumn extends PostgresqlColumn {
91
+ toSqlType(): string;
92
+ }
93
+ export declare class RealColumn extends PostgresqlColumn<number> {
94
+ toSqlType(): string;
95
+ }
96
+ export declare class SerialColumn extends PostgresqlColumn<number> {
97
+ toSqlType(): string;
98
+ }
99
+ export declare class SmallintColumn extends PostgresqlColumn<number> {
100
+ toSqlType(): string;
101
+ }
102
+ export declare class SmallserialColumn extends PostgresqlColumn<number> {
103
+ toSqlType(): string;
104
+ }
105
+ export declare class TextColumn extends PostgresqlColumn<string> {
106
+ toSqlType(): string;
107
+ }
108
+ export declare class TimeColumn extends PostgresqlColumn<string> {
109
+ toSqlType(): string;
110
+ }
111
+ export declare class TimestampColumn extends PostgresqlColumn<Date> {
112
+ protected $options: TimestampOptions | undefined;
113
+ constructor(name: string, options?: TimestampOptions);
114
+ toSqlType(): string;
115
+ }
116
+ export declare class UuidColumn extends PostgresqlColumn<string> {
117
+ toSqlType(): string;
118
+ }
119
+ export declare class VarcharColumn extends PostgresqlColumn<string> {
120
+ protected $options: VarcharOptions | undefined;
121
+ constructor(name: string, options?: VarcharOptions);
122
+ toSqlType(): string;
123
+ }
124
+ export declare class PostgresqlUniqueConstraint extends UniqueConstraint {
125
+ nullsNotDistinct<This>(this: This): This & Record<"nullsNotDistinct", never>;
126
+ }
127
+ export declare class PostgresqlCheckConstraint extends CheckConstraint {
128
+ }
129
+ export declare class PostgresqlPrimaryKeyConstraint extends PrimaryKeyConstraint {
130
+ }
131
+ export declare class PostgresqlForeignKeyConstraint extends ForeignKeyConstraint {
132
+ }
133
+ export declare class PostgresqlIndex extends Index {
134
+ onOnly<This>(this: This): This & Record<"onOnly", never>;
135
+ using<This>(this: This): This & Record<"using", never>;
136
+ concurrently<This>(this: This): This & Record<"concurrently", never>;
137
+ where<This>(this: This): This & Record<"where", never>;
138
+ with<This>(this: This): This & Record<"with", never>;
139
+ }
140
+ export declare class PostgresqlUniqueIndex extends UniqueIndex {
141
+ onOnly<This>(this: This): This & Record<"onOnly", never>;
142
+ using<This>(this: This): This & Record<"using", never>;
143
+ concurrently<This>(this: This): This & Record<"concurrently", never>;
144
+ where<This>(this: This): This & Record<"where", never>;
145
+ with<This>(this: This): This & Record<"with", never>;
146
+ }
147
+ export declare class PostgresqlSelectStatement<TSelection = Table | Record<string, Column>, TMode extends SelectMode = TSelection extends Table ? "single" : "partial", TNullability extends Record<string, boolean> = TSelection extends Table ? Record<TSelection["$name"], false> : {}> extends SelectStatement<TSelection, TMode, TNullability> {
148
+ fullJoin<TTable extends Table>(table: TTable, on: Sql): PostgresqlSelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "full">>;
149
+ }
150
+ export declare class PostgresqlInsertStatement<T extends Table> extends InsertStatement<T> {
151
+ }
152
+ export declare class PostgresqlUpdateStatement<T extends Table> extends UpdateStatement<T> {
153
+ }
154
+ export declare class PostgresqlDeleteStatement<T extends Table> extends DeleteStatement<T> {
155
+ }
156
+ export declare class PostgresqlTable<TName extends string = string, TColumns extends Record<string, PostgresqlColumn> = Record<string, PostgresqlColumn>> extends Table<TName, TColumns> {
157
+ }
158
+ export declare class PostgresqlMigration extends Migration {
159
+ readonly $dialect = "postgresql";
160
+ protected quoteIdentifier(value: string): string;
161
+ }
162
+ export declare class PostgresqlDatabase<T extends Record<string, PostgresqlTable>> extends Database<T> {
163
+ readonly $migration: PostgresqlMigration;
164
+ constructor(session: Session, schema: T);
165
+ select<T extends Table | Record<string, Column>>(value: T): PostgresqlSelectStatement<T, T extends Table<string, Record<string, Column<unknown>>> ? "single" : "partial", T extends Table<string, Record<string, Column<unknown>>> ? Record<T["$name"], false> : {}>;
166
+ insert<T extends Table>(table: T): PostgresqlInsertStatement<T>;
167
+ update<T extends Table>(table: T): PostgresqlUpdateStatement<T>;
168
+ delete<T extends Table>(table: T): PostgresqlDeleteStatement<T>;
169
+ }
170
+ export declare function bigint(name: string): BigintColumn;
171
+ export declare function bigserial(name: string): BigserialColumn;
172
+ export declare function boolean(name: string): BooleanColumn;
173
+ export declare function char(name: string, options?: CharOptions): CharColumn;
174
+ export declare function cidr(name: string): CidrColumn;
175
+ export declare function date(name: string, options?: DateOptions): DateColumn;
176
+ export declare function decimal(name: string, options?: DecimalOptions): DecimalColumn;
177
+ export declare function doublePrecision(name: string): DoublePrecisionColumn;
178
+ export declare function inet(name: string): InetColumn;
179
+ export declare function integer(name: string): IntegerColumn;
180
+ export declare function interval(name: string): IntervalColumn;
181
+ export declare function json(name: string): JsonColumn;
182
+ export declare function jsonb(name: string): JsonbColumn;
183
+ export declare function line(name: string): LineColumn;
184
+ export declare function macaddr(name: string): MacaddrColumn;
185
+ export declare function macaddr8(name: string): Macaddr8Column;
186
+ export declare function numeric(name: string, options?: NumericOptions): NumericColumn;
187
+ export declare function enumeration(name: string): EnumerationColumn;
188
+ export declare function point(name: string): PointColumn;
189
+ export declare function real(name: string): RealColumn;
190
+ export declare function serial(name: string): SerialColumn;
191
+ export declare function smallint(name: string): SmallintColumn;
192
+ export declare function smallserial(name: string): SmallserialColumn;
193
+ export declare function text(name: string): TextColumn;
194
+ export declare function time(name: string): TimeColumn;
195
+ export declare function timestamp(name: string, options?: TimestampOptions): TimestampColumn;
196
+ export declare function uuid(name: string): UuidColumn;
197
+ export declare function varchar(name: string, options?: VarcharOptions): VarcharColumn;
198
+ export declare function unique(...columns: Array<Column>): PostgresqlUniqueConstraint;
199
+ export declare function check(value: Sql): PostgresqlCheckConstraint;
200
+ export declare function primaryKey(...columns: Array<Column>): PostgresqlPrimaryKeyConstraint;
201
+ export declare function foreignKey(columns: Array<Column>, foreignColumns: Array<Column>): PostgresqlForeignKeyConstraint;
202
+ export declare function index(...columns: Array<Column>): PostgresqlIndex;
203
+ export declare function uniqueIndex(...columns: Array<Column>): PostgresqlUniqueIndex;
204
+ export declare function table<TName extends string, TColumns extends Record<string, PostgresqlColumn>>(name: TName, columns: TColumns, definitions?: (columns: TColumns) => Array<Definition>): PostgresqlTable<TName, TColumns> & TColumns;
@@ -0,0 +1,373 @@
1
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, combine, sql } from "../index.js";
2
+ //#region src/protocols/postgresql.ts
3
+ var PostgresqlColumn = class extends Column {
4
+ generatedAlwaysAsIdentity() {
5
+ return this;
6
+ }
7
+ type() {
8
+ return this;
9
+ }
10
+ };
11
+ var BigintColumn = class extends PostgresqlColumn {
12
+ toSqlType() {
13
+ return "bigint";
14
+ }
15
+ };
16
+ var BigserialColumn = class extends PostgresqlColumn {
17
+ toSqlType() {
18
+ return "bigserial";
19
+ }
20
+ };
21
+ var BooleanColumn = class extends PostgresqlColumn {
22
+ toSqlType() {
23
+ return "boolean";
24
+ }
25
+ };
26
+ var CharColumn = class extends PostgresqlColumn {
27
+ $options;
28
+ constructor(name, options) {
29
+ super(name);
30
+ this.$options = options;
31
+ }
32
+ toSqlType() {
33
+ return this.$options?.length === void 0 ? "char" : `char(${this.$options.length})`;
34
+ }
35
+ };
36
+ var CidrColumn = class extends PostgresqlColumn {
37
+ toSqlType() {
38
+ return "cidr";
39
+ }
40
+ };
41
+ var DateColumn = class extends PostgresqlColumn {
42
+ $options;
43
+ constructor(name, options) {
44
+ super(name);
45
+ this.$options = options;
46
+ }
47
+ toSqlType() {
48
+ return "date";
49
+ }
50
+ };
51
+ var DecimalColumn = class extends PostgresqlColumn {
52
+ $options;
53
+ constructor(name, options) {
54
+ super(name);
55
+ this.$options = options;
56
+ }
57
+ toSqlType() {
58
+ return this.$options === void 0 ? "numeric" : `numeric(${this.$options.precision}, ${this.$options.scale})`;
59
+ }
60
+ };
61
+ var DoublePrecisionColumn = class extends PostgresqlColumn {
62
+ toSqlType() {
63
+ return "double precision";
64
+ }
65
+ };
66
+ var InetColumn = class extends PostgresqlColumn {
67
+ toSqlType() {
68
+ return "inet";
69
+ }
70
+ };
71
+ var IntegerColumn = class extends PostgresqlColumn {
72
+ toSqlType() {
73
+ return "integer";
74
+ }
75
+ };
76
+ var IntervalColumn = class extends PostgresqlColumn {
77
+ toSqlType() {
78
+ return "interval";
79
+ }
80
+ };
81
+ var JsonColumn = class extends PostgresqlColumn {
82
+ toSqlType() {
83
+ return "json";
84
+ }
85
+ };
86
+ var JsonbColumn = class extends PostgresqlColumn {
87
+ toSqlType() {
88
+ return "jsonb";
89
+ }
90
+ };
91
+ var LineColumn = class extends PostgresqlColumn {
92
+ toSqlType() {
93
+ return "line";
94
+ }
95
+ };
96
+ var MacaddrColumn = class extends PostgresqlColumn {
97
+ toSqlType() {
98
+ return "macaddr";
99
+ }
100
+ };
101
+ var Macaddr8Column = class extends PostgresqlColumn {
102
+ toSqlType() {
103
+ return "macaddr8";
104
+ }
105
+ };
106
+ var NumericColumn = class extends PostgresqlColumn {
107
+ $options;
108
+ constructor(name, options) {
109
+ super(name);
110
+ this.$options = options;
111
+ }
112
+ toSqlType() {
113
+ return this.$options === void 0 ? "numeric" : `numeric(${this.$options.precision}, ${this.$options.scale})`;
114
+ }
115
+ };
116
+ var EnumerationColumn = class extends PostgresqlColumn {
117
+ toSqlType() {
118
+ return "enum";
119
+ }
120
+ };
121
+ var PointColumn = class extends PostgresqlColumn {
122
+ toSqlType() {
123
+ return "point";
124
+ }
125
+ };
126
+ var RealColumn = class extends PostgresqlColumn {
127
+ toSqlType() {
128
+ return "real";
129
+ }
130
+ };
131
+ var SerialColumn = class extends PostgresqlColumn {
132
+ toSqlType() {
133
+ return "serial";
134
+ }
135
+ };
136
+ var SmallintColumn = class extends PostgresqlColumn {
137
+ toSqlType() {
138
+ return "smallint";
139
+ }
140
+ };
141
+ var SmallserialColumn = class extends PostgresqlColumn {
142
+ toSqlType() {
143
+ return "smallserial";
144
+ }
145
+ };
146
+ var TextColumn = class extends PostgresqlColumn {
147
+ toSqlType() {
148
+ return "text";
149
+ }
150
+ };
151
+ var TimeColumn = class extends PostgresqlColumn {
152
+ toSqlType() {
153
+ return "time";
154
+ }
155
+ };
156
+ var TimestampColumn = class extends PostgresqlColumn {
157
+ $options;
158
+ constructor(name, options) {
159
+ super(name);
160
+ this.$options = options;
161
+ }
162
+ toSqlType() {
163
+ return this.$options?.precision === void 0 ? "timestamp" : `timestamp(${this.$options.precision})`;
164
+ }
165
+ };
166
+ var UuidColumn = class extends PostgresqlColumn {
167
+ toSqlType() {
168
+ return "uuid";
169
+ }
170
+ };
171
+ var VarcharColumn = class extends PostgresqlColumn {
172
+ $options;
173
+ constructor(name, options) {
174
+ super(name);
175
+ this.$options = options;
176
+ }
177
+ toSqlType() {
178
+ return this.$options?.length === void 0 ? "varchar" : `varchar(${this.$options.length})`;
179
+ }
180
+ };
181
+ var PostgresqlUniqueConstraint = class extends UniqueConstraint {
182
+ nullsNotDistinct() {
183
+ return this;
184
+ }
185
+ };
186
+ var PostgresqlCheckConstraint = class extends CheckConstraint {};
187
+ var PostgresqlPrimaryKeyConstraint = class extends PrimaryKeyConstraint {};
188
+ var PostgresqlForeignKeyConstraint = class extends ForeignKeyConstraint {};
189
+ var PostgresqlIndex = class extends Index {
190
+ onOnly() {
191
+ return this;
192
+ }
193
+ using() {
194
+ return this;
195
+ }
196
+ concurrently() {
197
+ return this;
198
+ }
199
+ where() {
200
+ return this;
201
+ }
202
+ with() {
203
+ return this;
204
+ }
205
+ };
206
+ var PostgresqlUniqueIndex = class extends UniqueIndex {
207
+ onOnly() {
208
+ return this;
209
+ }
210
+ using() {
211
+ return this;
212
+ }
213
+ concurrently() {
214
+ return this;
215
+ }
216
+ where() {
217
+ return this;
218
+ }
219
+ with() {
220
+ return this;
221
+ }
222
+ };
223
+ var PostgresqlSelectStatement = class extends SelectStatement {
224
+ fullJoin(table, on) {
225
+ this.push(sql`FULL JOIN ${table} ON ${on}`);
226
+ if (this.$value instanceof Table) {
227
+ this.$selection.push(", ", combine(Object.values(table.$columns), ", "));
228
+ this.$baseNullable = true;
229
+ this.$joins.forEach((join) => join.nullable = true);
230
+ this.$joins.push({
231
+ table,
232
+ nullable: true
233
+ });
234
+ }
235
+ return this;
236
+ }
237
+ };
238
+ var PostgresqlInsertStatement = class extends InsertStatement {};
239
+ var PostgresqlUpdateStatement = class extends UpdateStatement {};
240
+ var PostgresqlDeleteStatement = class extends DeleteStatement {};
241
+ var PostgresqlTable = class extends Table {};
242
+ var PostgresqlMigration = class extends Migration {
243
+ $dialect = "postgresql";
244
+ quoteIdentifier(value) {
245
+ return `"${value.replaceAll("\"", "\"\"")}"`;
246
+ }
247
+ };
248
+ var PostgresqlDatabase = class extends Database {
249
+ $migration;
250
+ constructor(session, schema) {
251
+ super(session, schema);
252
+ this.$migration = new PostgresqlMigration();
253
+ }
254
+ select(value) {
255
+ return new PostgresqlSelectStatement(this.$session, value);
256
+ }
257
+ insert(table) {
258
+ return new PostgresqlInsertStatement(this.$session, table);
259
+ }
260
+ update(table) {
261
+ return new PostgresqlUpdateStatement(this.$session, table);
262
+ }
263
+ delete(table) {
264
+ return new PostgresqlDeleteStatement(this.$session, table);
265
+ }
266
+ };
267
+ function bigint(name) {
268
+ return new BigintColumn(name);
269
+ }
270
+ function bigserial(name) {
271
+ return new BigserialColumn(name);
272
+ }
273
+ function boolean(name) {
274
+ return new BooleanColumn(name);
275
+ }
276
+ function char(name, options) {
277
+ return new CharColumn(name, options);
278
+ }
279
+ function cidr(name) {
280
+ return new CidrColumn(name);
281
+ }
282
+ function date(name, options) {
283
+ return new DateColumn(name, options);
284
+ }
285
+ function decimal(name, options) {
286
+ return new DecimalColumn(name, options);
287
+ }
288
+ function doublePrecision(name) {
289
+ return new DoublePrecisionColumn(name);
290
+ }
291
+ function inet(name) {
292
+ return new InetColumn(name);
293
+ }
294
+ function integer(name) {
295
+ return new IntegerColumn(name);
296
+ }
297
+ function interval(name) {
298
+ return new IntervalColumn(name);
299
+ }
300
+ function json(name) {
301
+ return new JsonColumn(name);
302
+ }
303
+ function jsonb(name) {
304
+ return new JsonbColumn(name);
305
+ }
306
+ function line(name) {
307
+ return new LineColumn(name);
308
+ }
309
+ function macaddr(name) {
310
+ return new MacaddrColumn(name);
311
+ }
312
+ function macaddr8(name) {
313
+ return new Macaddr8Column(name);
314
+ }
315
+ function numeric(name, options) {
316
+ return new NumericColumn(name, options);
317
+ }
318
+ function enumeration(name) {
319
+ return new EnumerationColumn(name);
320
+ }
321
+ function point(name) {
322
+ return new PointColumn(name);
323
+ }
324
+ function real(name) {
325
+ return new RealColumn(name);
326
+ }
327
+ function serial(name) {
328
+ return new SerialColumn(name);
329
+ }
330
+ function smallint(name) {
331
+ return new SmallintColumn(name);
332
+ }
333
+ function smallserial(name) {
334
+ return new SmallserialColumn(name);
335
+ }
336
+ function text(name) {
337
+ return new TextColumn(name);
338
+ }
339
+ function time(name) {
340
+ return new TimeColumn(name);
341
+ }
342
+ function timestamp(name, options) {
343
+ return new TimestampColumn(name, options);
344
+ }
345
+ function uuid(name) {
346
+ return new UuidColumn(name);
347
+ }
348
+ function varchar(name, options) {
349
+ return new VarcharColumn(name, options);
350
+ }
351
+ function unique(...columns) {
352
+ return new PostgresqlUniqueConstraint(...columns);
353
+ }
354
+ function check(value) {
355
+ return new PostgresqlCheckConstraint(value);
356
+ }
357
+ function primaryKey(...columns) {
358
+ return new PostgresqlPrimaryKeyConstraint(...columns);
359
+ }
360
+ function foreignKey(columns, foreignColumns) {
361
+ return new PostgresqlForeignKeyConstraint(columns, foreignColumns);
362
+ }
363
+ function index(...columns) {
364
+ return new PostgresqlIndex(...columns);
365
+ }
366
+ function uniqueIndex(...columns) {
367
+ return new PostgresqlUniqueIndex(...columns);
368
+ }
369
+ function table(name, columns, definitions) {
370
+ return Object.assign(new PostgresqlTable(name, columns, definitions?.(columns) ?? []), columns);
371
+ }
372
+ //#endregion
373
+ export { BigintColumn, BigserialColumn, BooleanColumn, CharColumn, CidrColumn, DateColumn, DecimalColumn, DoublePrecisionColumn, EnumerationColumn, InetColumn, IntegerColumn, IntervalColumn, JsonColumn, JsonbColumn, LineColumn, Macaddr8Column, MacaddrColumn, NumericColumn, PointColumn, PostgresqlCheckConstraint, PostgresqlColumn, PostgresqlDatabase, PostgresqlDeleteStatement, PostgresqlForeignKeyConstraint, PostgresqlIndex, PostgresqlInsertStatement, PostgresqlMigration, PostgresqlPrimaryKeyConstraint, PostgresqlSelectStatement, PostgresqlTable, PostgresqlUniqueConstraint, PostgresqlUniqueIndex, PostgresqlUpdateStatement, RealColumn, SerialColumn, SmallintColumn, SmallserialColumn, TextColumn, TimeColumn, TimestampColumn, UuidColumn, VarcharColumn, bigint, bigserial, boolean, char, check, cidr, date, decimal, doublePrecision, enumeration, foreignKey, index, inet, integer, interval, json, jsonb, line, macaddr, macaddr8, numeric, point, primaryKey, real, serial, smallint, smallserial, table, text, time, timestamp, unique, uniqueIndex, uuid, varchar };
@@ -0,0 +1,96 @@
1
+ import type { Primitive } from "revojs/shared";
2
+ import { CheckConstraint, Column, Database, DeleteStatement, ForeignKeyConstraint, Index, InsertStatement, Migration, PrimaryKeyConstraint, SelectStatement, Table, UniqueConstraint, UniqueIndex, UpdateStatement, type AppendToNullabilityMap, type AppendToSelection, type ColumnMeta, type Definition, type DeleteConstraintChange, type MigrationContext, type SelectMode, type Session, type Sql, type UpdateColumnChange } from "../index";
3
+ export type IntegerMode = "number" | "timestamp" | "timestamp_ms" | "boolean";
4
+ export type IntegerData<TMode> = TMode extends "timestamp" | "timestamp_ms" ? Date : TMode extends "boolean" ? boolean : number;
5
+ export type TextMode = "text" | "json";
6
+ export type TextData<TMode> = TMode extends "json" ? unknown : string;
7
+ export interface IntegerOptions<TMode = IntegerMode> {
8
+ mode?: TMode;
9
+ }
10
+ export interface TextOptions<TMode = TextMode> {
11
+ mode?: TMode;
12
+ }
13
+ export interface SqliteColumnMeta<TMode extends string = string> extends ColumnMeta {
14
+ mode?: TMode;
15
+ }
16
+ export declare abstract class SqliteColumn<TDataType = unknown> extends Column<TDataType> {
17
+ type<TData>(): this & Record<"$type", TData>;
18
+ }
19
+ export declare class BlobColumn extends SqliteColumn<Uint8Array> {
20
+ toSqlType(): string;
21
+ }
22
+ export declare class IntegerColumn<TMode extends IntegerMode = "number"> extends SqliteColumn<IntegerData<TMode>> {
23
+ readonly $options: IntegerOptions<TMode> | undefined;
24
+ constructor(name: string, options?: IntegerOptions<TMode>);
25
+ toSqlType(): string;
26
+ toMeta(): SqliteColumnMeta<TMode>;
27
+ fromDriverValue(value: unknown): IntegerData<TMode>;
28
+ toDriverValue(value: IntegerData<TMode>): Primitive;
29
+ }
30
+ export declare class NumericColumn extends SqliteColumn<number> {
31
+ toSqlType(): string;
32
+ }
33
+ export declare class RealColumn extends SqliteColumn<number> {
34
+ toSqlType(): string;
35
+ }
36
+ export declare class TextColumn<TMode extends TextMode = "text"> extends SqliteColumn<TextData<TMode>> {
37
+ readonly $options: TextOptions<TMode> | undefined;
38
+ constructor(name: string, options?: TextOptions<TMode>);
39
+ toSqlType(): string;
40
+ toMeta(): SqliteColumnMeta<TMode>;
41
+ fromDriverValue(value: unknown): TextData<TMode>;
42
+ toDriverValue(value: TextData<TMode>): Primitive;
43
+ }
44
+ export declare class SqliteUniqueConstraint extends UniqueConstraint {
45
+ }
46
+ export declare class SqliteCheckConstraint extends CheckConstraint {
47
+ }
48
+ export declare class SqlitePrimaryKeyConstraint extends PrimaryKeyConstraint {
49
+ }
50
+ export declare class SqliteForeignKeyConstraint extends ForeignKeyConstraint {
51
+ }
52
+ export declare class SqliteIndex extends Index {
53
+ where<This>(this: This): This & Record<"where", never>;
54
+ }
55
+ export declare class SqliteUniqueIndex extends UniqueIndex {
56
+ where<This>(this: This): This & Record<"where", never>;
57
+ }
58
+ export declare class SqliteSelectStatement<TSelection = Table | Record<string, Column>, TMode extends SelectMode = TSelection extends Table ? "single" : "partial", TNullability extends Record<string, boolean> = TSelection extends Table ? Record<TSelection["$name"], false> : {}> extends SelectStatement<TSelection, TMode, TNullability> {
59
+ fullJoin<TTable extends Table>(table: TTable, on: Sql): SqliteSelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "full">>;
60
+ }
61
+ export declare class SqliteInsertStatement<T extends Table> extends InsertStatement<T> {
62
+ }
63
+ export declare class SqliteUpdateStatement<T extends Table> extends UpdateStatement<T> {
64
+ }
65
+ export declare class SqliteDeleteStatement<T extends Table> extends DeleteStatement<T> {
66
+ }
67
+ export declare class SqliteTable<TName extends string = string, TColumns extends Record<string, SqliteColumn> = Record<string, SqliteColumn>> extends Table<TName, TColumns> {
68
+ }
69
+ export declare class SqliteMigration extends Migration {
70
+ readonly $dialect = "sqlite";
71
+ protected render({ changes, current }: MigrationContext): string[];
72
+ protected toUpdateColumnChange(change: UpdateColumnChange): Array<string>;
73
+ protected toDeleteConstraintChange(change: DeleteConstraintChange): Array<string>;
74
+ protected quoteIdentifier(value: string): string;
75
+ protected serializeLiteral(value: string | number | boolean | null): string;
76
+ }
77
+ export declare class SqliteDatabase<T extends Record<string, SqliteTable>> extends Database<T> {
78
+ readonly $migration: SqliteMigration;
79
+ constructor(session: Session, schema: T);
80
+ select<T extends Table | Record<string, Column>>(value: T): SqliteSelectStatement<T, T extends Table<string, Record<string, Column<unknown>>> ? "single" : "partial", T extends Table<string, Record<string, Column<unknown>>> ? Record<T["$name"], false> : {}>;
81
+ insert<T extends Table>(table: T): SqliteInsertStatement<T>;
82
+ update<T extends Table>(table: T): SqliteUpdateStatement<T>;
83
+ delete<T extends Table>(table: T): SqliteDeleteStatement<T>;
84
+ }
85
+ export declare function blob(name: string): BlobColumn;
86
+ export declare function integer<TMode extends IntegerMode = "number">(name: string, options?: IntegerOptions<TMode>): IntegerColumn<TMode>;
87
+ export declare function numeric(name: string): NumericColumn;
88
+ export declare function real(name: string): RealColumn;
89
+ export declare function text<TMode extends TextMode = "text">(name: string, options?: TextOptions<TMode>): TextColumn<TMode>;
90
+ export declare function unique(...columns: Array<Column>): SqliteUniqueConstraint;
91
+ export declare function check(value: Sql): SqliteCheckConstraint;
92
+ export declare function primaryKey(...columns: Array<Column>): SqlitePrimaryKeyConstraint;
93
+ export declare function foreignKey(columns: Array<Column>, foreignColumns: Array<Column>): SqliteForeignKeyConstraint;
94
+ export declare function index(...columns: Array<Column>): SqliteIndex;
95
+ export declare function uniqueIndex(...columns: Array<Column>): SqliteUniqueIndex;
96
+ export declare function table<TName extends string, TColumns extends Record<string, SqliteColumn>>(name: TName, columns: TColumns, definitions?: (columns: TColumns) => Array<Definition>): SqliteTable<TName, TColumns> & TColumns;