@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.
- package/dist/commands/generate.d.ts +8 -0
- package/dist/commands/generate.js +48 -0
- package/dist/index.d.ts +360 -0
- package/dist/index.js +842 -0
- package/dist/module/index.d.ts +3 -0
- package/dist/module/index.js +19 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +15 -0
- package/dist/protocols/mysql.d.ts +175 -0
- package/dist/protocols/mysql.js +327 -0
- package/dist/protocols/postgresql.d.ts +204 -0
- package/dist/protocols/postgresql.js +373 -0
- package/dist/protocols/sqlite.d.ts +96 -0
- package/dist/protocols/sqlite.js +217 -0
- package/dist/providers/bun-sqlite.d.ts +18 -0
- package/dist/providers/bun-sqlite.js +37 -0
- package/dist/providers/d1.d.ts +18 -0
- package/dist/providers/d1.js +37 -0
- package/dist/types/index.d.ts +14 -0
- package/package.json +48 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { VARIABLE_CONTEXT } from "revojs";
|
|
2
|
+
import storage from "#storage";
|
|
3
|
+
import { defineCommand } from "revojs/module";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "fs";
|
|
5
|
+
import { join, resolve } from "path";
|
|
6
|
+
import { loadEnv } from "vite";
|
|
7
|
+
//#region src/commands/generate.ts
|
|
8
|
+
var generate_default = defineCommand({
|
|
9
|
+
description: "Generate migration files from the storage schema",
|
|
10
|
+
arguments: { directory: {
|
|
11
|
+
type: "string",
|
|
12
|
+
short: "d",
|
|
13
|
+
description: "Migration output directory"
|
|
14
|
+
} },
|
|
15
|
+
async run({ arguments: { directory: output = "migrations" }, environment }) {
|
|
16
|
+
const databases = Object.values(storage).flatMap((source) => Object.entries(source));
|
|
17
|
+
if (databases.length === 0) {
|
|
18
|
+
console.log("No storage databases found.");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const scope = {
|
|
22
|
+
hooks: {},
|
|
23
|
+
context: { [VARIABLE_CONTEXT]: loadEnv(environment.config.mode, environment.config.envDir, "") }
|
|
24
|
+
};
|
|
25
|
+
for (const [name, load] of databases) {
|
|
26
|
+
const database = (await load())(scope);
|
|
27
|
+
const current = database.toMeta();
|
|
28
|
+
const directory = resolve(output, name);
|
|
29
|
+
const snapshot = (existsSync(directory) ? readdirSync(directory) : []).sort().reverse().map((entry) => join(directory, entry, "meta.json")).find((path) => existsSync(path));
|
|
30
|
+
const changes = database.$migration.diff(snapshot ? JSON.parse(readFileSync(snapshot, "utf8")) : void 0, current);
|
|
31
|
+
if (changes.length === 0) {
|
|
32
|
+
console.log(`No schema changes detected for "${name}".`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "").slice(0, 14);
|
|
36
|
+
let order = timestamp;
|
|
37
|
+
for (let index = 2; existsSync(join(directory, order)); index++) order = `${timestamp}-${index}`;
|
|
38
|
+
const target = join(directory, order);
|
|
39
|
+
const statements = database.$migration.toSql(changes, current);
|
|
40
|
+
mkdirSync(target, { recursive: true });
|
|
41
|
+
writeFileSync(join(target, "meta.json"), `${JSON.stringify(current, null, 4)}\n`);
|
|
42
|
+
writeFileSync(join(target, "migration.sql"), statements.length ? `${statements.join("\n\n")}\n` : "");
|
|
43
|
+
console.log(`Created migration "${name}/${order}" with ${changes.length} change(s).`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
//#endregion
|
|
48
|
+
export { generate_default as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { type Scope, type Source, type SourceScope, type SourceValue } from "revojs";
|
|
2
|
+
import type { Primitive } from "revojs/shared";
|
|
3
|
+
export type DefaultValue<T> = undefined | T | (() => T);
|
|
4
|
+
export type References = undefined | (() => Column);
|
|
5
|
+
export type ReferentialAction = "cascade" | "restrict" | "no action" | "set null" | "set default";
|
|
6
|
+
export interface ReferentialActions {
|
|
7
|
+
onDelete?: ReferentialAction;
|
|
8
|
+
onUpdate?: ReferentialAction;
|
|
9
|
+
}
|
|
10
|
+
export type Chunk = Primitive | Parameter | Sql | Table | Column;
|
|
11
|
+
export type Definition = CheckConstraint | ForeignKeyConstraint | Index | PrimaryKeyConstraint | UniqueConstraint | UniqueIndex;
|
|
12
|
+
export interface Base {
|
|
13
|
+
toSql: () => Sql;
|
|
14
|
+
}
|
|
15
|
+
export interface Query<T = unknown> {
|
|
16
|
+
sql: string;
|
|
17
|
+
parameters: Array<Primitive>;
|
|
18
|
+
}
|
|
19
|
+
export type IsNotNull<T> = T extends Record<"notNull", never> | Record<"primaryKey", never> ? true : false;
|
|
20
|
+
export type HasDefault<T> = T extends Record<"default", never> ? true : false;
|
|
21
|
+
export type IsRequired<T> = HasDefault<T> extends true ? false : IsNotNull<T>;
|
|
22
|
+
export type Data<T> = T extends Record<"$type", infer TData> ? TData : T extends Column<infer TData> ? TData : never;
|
|
23
|
+
export type SelectValue<T> = IsNotNull<T> extends true ? Data<T> : Data<T> | null;
|
|
24
|
+
export type InferColumns<T> = {
|
|
25
|
+
[Key in keyof T as T[Key] extends Column ? Key : never]: SelectValue<T[Key]>;
|
|
26
|
+
};
|
|
27
|
+
export type RequiredKeys<T> = {
|
|
28
|
+
[Key in keyof InferColumns<T>]-?: IsRequired<T[Key]> extends true ? Key : never;
|
|
29
|
+
}[keyof InferColumns<T>];
|
|
30
|
+
export type InferModelFromColumns<T, TMode extends "select" | "insert" = "select"> = TMode extends "insert" ? Partial<InferColumns<T>> & Pick<InferColumns<T>, RequiredKeys<T>> : InferColumns<T>;
|
|
31
|
+
export type InferSelectModel<T extends Table> = InferModelFromColumns<T>;
|
|
32
|
+
export type InferInsertModel<T extends Table> = InferModelFromColumns<T, "insert">;
|
|
33
|
+
export type SelectMode = "partial" | "single" | "multiple";
|
|
34
|
+
export type JoinType = "left" | "right" | "inner" | "cross" | "full";
|
|
35
|
+
export type SelectResult<TSelection, TMode extends SelectMode, TNullability extends Record<string, boolean>> = TMode extends "partial" ? InferColumns<TSelection> : TMode extends "single" ? TSelection extends Table ? InferSelectModel<TSelection> : never : {
|
|
36
|
+
[Key in keyof TSelection]: TSelection[Key] extends Table ? Key extends keyof TNullability ? TNullability[Key] extends true ? InferSelectModel<TSelection[Key]> | null : InferSelectModel<TSelection[Key]> : never : never;
|
|
37
|
+
};
|
|
38
|
+
export type AppendToSelection<TSelection, TTable extends Table, TMode extends SelectMode> = TMode extends "partial" ? TSelection : TMode extends "single" ? TSelection extends Table ? Record<TSelection["$name"], TSelection> & Record<TTable["$name"], TTable> : never : TSelection & Record<TTable["$name"], TTable>;
|
|
39
|
+
export type AppendToNullabilityMap<TNullability extends Record<string, boolean>, TTable extends Table, TJoinType extends JoinType> = TJoinType extends "left" ? TNullability & Record<TTable["$name"], true> : TJoinType extends "right" ? {
|
|
40
|
+
[Key in keyof TNullability]: true;
|
|
41
|
+
} & Record<TTable["$name"], false> : TJoinType extends "full" ? {
|
|
42
|
+
[Key in keyof TNullability]: true;
|
|
43
|
+
} & Record<TTable["$name"], true> : TNullability & Record<TTable["$name"], false>;
|
|
44
|
+
export interface PrimaryKeyConstraintMeta {
|
|
45
|
+
kind: "primaryKey";
|
|
46
|
+
columns: Array<string>;
|
|
47
|
+
}
|
|
48
|
+
export interface UniqueConstraintMeta {
|
|
49
|
+
kind: "unique";
|
|
50
|
+
columns: Array<string>;
|
|
51
|
+
}
|
|
52
|
+
export interface ForeignKeyConstraintMeta {
|
|
53
|
+
kind: "foreignKey";
|
|
54
|
+
columns: Array<string>;
|
|
55
|
+
foreignTable: string;
|
|
56
|
+
foreignColumns: Array<string>;
|
|
57
|
+
onDelete?: ReferentialAction;
|
|
58
|
+
onUpdate?: ReferentialAction;
|
|
59
|
+
}
|
|
60
|
+
export interface CheckConstraintMeta {
|
|
61
|
+
kind: "check";
|
|
62
|
+
sql: string;
|
|
63
|
+
parameters: Array<string | number | boolean | null>;
|
|
64
|
+
}
|
|
65
|
+
export interface IndexMeta {
|
|
66
|
+
kind: "index";
|
|
67
|
+
columns: Array<string>;
|
|
68
|
+
}
|
|
69
|
+
export interface UniqueIndexMeta {
|
|
70
|
+
kind: "uniqueIndex";
|
|
71
|
+
columns: Array<string>;
|
|
72
|
+
}
|
|
73
|
+
export type ConstraintMeta = PrimaryKeyConstraintMeta | UniqueConstraintMeta | ForeignKeyConstraintMeta | CheckConstraintMeta;
|
|
74
|
+
export type IndexDefinitionMeta = IndexMeta | UniqueIndexMeta;
|
|
75
|
+
export type DefinitionMeta = ConstraintMeta | IndexDefinitionMeta;
|
|
76
|
+
export interface ColumnMeta {
|
|
77
|
+
name: string;
|
|
78
|
+
type: string;
|
|
79
|
+
notNull: boolean;
|
|
80
|
+
primaryKey: boolean;
|
|
81
|
+
unique: boolean;
|
|
82
|
+
references?: ReferenceMeta;
|
|
83
|
+
}
|
|
84
|
+
export interface ReferenceMeta {
|
|
85
|
+
table: string;
|
|
86
|
+
column: string;
|
|
87
|
+
onDelete?: ReferentialAction;
|
|
88
|
+
onUpdate?: ReferentialAction;
|
|
89
|
+
}
|
|
90
|
+
export interface TableMeta {
|
|
91
|
+
name: string;
|
|
92
|
+
columns: Record<string, ColumnMeta>;
|
|
93
|
+
definitions: Array<DefinitionMeta>;
|
|
94
|
+
}
|
|
95
|
+
export interface DatabaseMeta {
|
|
96
|
+
dialect: string;
|
|
97
|
+
tables: Array<TableMeta>;
|
|
98
|
+
}
|
|
99
|
+
export interface CreateTableChange {
|
|
100
|
+
kind: "createTable";
|
|
101
|
+
table: TableMeta;
|
|
102
|
+
}
|
|
103
|
+
export interface DeleteTableChange {
|
|
104
|
+
kind: "deleteTable";
|
|
105
|
+
table: TableMeta;
|
|
106
|
+
}
|
|
107
|
+
export interface CreateColumnChange {
|
|
108
|
+
kind: "createColumn";
|
|
109
|
+
table: string;
|
|
110
|
+
column: ColumnMeta;
|
|
111
|
+
}
|
|
112
|
+
export interface UpdateColumnChange {
|
|
113
|
+
kind: "updateColumn";
|
|
114
|
+
table: string;
|
|
115
|
+
before: ColumnMeta;
|
|
116
|
+
after: ColumnMeta;
|
|
117
|
+
}
|
|
118
|
+
export interface DeleteColumnChange {
|
|
119
|
+
kind: "deleteColumn";
|
|
120
|
+
table: string;
|
|
121
|
+
column: ColumnMeta;
|
|
122
|
+
}
|
|
123
|
+
export interface CreateConstraintChange {
|
|
124
|
+
kind: "createConstraint";
|
|
125
|
+
table: string;
|
|
126
|
+
constraint: ConstraintMeta;
|
|
127
|
+
}
|
|
128
|
+
export interface DeleteConstraintChange {
|
|
129
|
+
kind: "deleteConstraint";
|
|
130
|
+
table: string;
|
|
131
|
+
constraint: ConstraintMeta;
|
|
132
|
+
}
|
|
133
|
+
export interface CreateIndexChange {
|
|
134
|
+
kind: "createIndex";
|
|
135
|
+
table: string;
|
|
136
|
+
index: IndexDefinitionMeta;
|
|
137
|
+
}
|
|
138
|
+
export interface DeleteIndexChange {
|
|
139
|
+
kind: "deleteIndex";
|
|
140
|
+
table: string;
|
|
141
|
+
index: IndexDefinitionMeta;
|
|
142
|
+
}
|
|
143
|
+
export type MetaChange = CreateTableChange | DeleteTableChange | CreateColumnChange | UpdateColumnChange | DeleteColumnChange | CreateConstraintChange | DeleteConstraintChange | CreateIndexChange | DeleteIndexChange;
|
|
144
|
+
interface ChangeFactory<T> {
|
|
145
|
+
create: (value: T) => MetaChange;
|
|
146
|
+
delete: (value: T) => MetaChange;
|
|
147
|
+
update?: (before: T, after: T) => MetaChange;
|
|
148
|
+
}
|
|
149
|
+
export interface MigrationContext {
|
|
150
|
+
changes: Array<MetaChange>;
|
|
151
|
+
current: DatabaseMeta;
|
|
152
|
+
}
|
|
153
|
+
export declare class Parameter {
|
|
154
|
+
readonly value: Primitive;
|
|
155
|
+
constructor(value: Primitive);
|
|
156
|
+
}
|
|
157
|
+
export declare class Sql<T = unknown> {
|
|
158
|
+
protected $chunks: Array<Chunk>;
|
|
159
|
+
constructor(...chunks: Array<Chunk>);
|
|
160
|
+
push(...chunks: Array<Chunk>): this;
|
|
161
|
+
toQuery(): Query<T>;
|
|
162
|
+
toSql(): this;
|
|
163
|
+
}
|
|
164
|
+
export declare abstract class Statement<T = unknown> extends Sql<T> {
|
|
165
|
+
protected $session: Session;
|
|
166
|
+
protected $fields: Array<[string, Column]>;
|
|
167
|
+
constructor(session: Session, value: Table | Record<string, Column>, ...chunks: Array<Chunk>);
|
|
168
|
+
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
169
|
+
protected mapRow(row: Array<unknown>): Record<string, unknown>;
|
|
170
|
+
}
|
|
171
|
+
export declare class SelectStatement<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 Statement<Array<SelectResult<TSelection, TMode, TNullability>>> {
|
|
172
|
+
protected $value: TSelection;
|
|
173
|
+
protected $selection: Sql;
|
|
174
|
+
protected $baseNullable: boolean;
|
|
175
|
+
protected $joins: {
|
|
176
|
+
table: Table;
|
|
177
|
+
nullable: boolean;
|
|
178
|
+
}[];
|
|
179
|
+
constructor(session: Session, value: TSelection);
|
|
180
|
+
from(table: Table): this & Record<"from", never>;
|
|
181
|
+
leftJoin<TTable extends Table>(table: TTable, on: Chunk): SelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "left">>;
|
|
182
|
+
rightJoin<TTable extends Table>(table: TTable, on: Chunk): SelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "right">>;
|
|
183
|
+
innerJoin<TTable extends Table>(table: TTable, on: Chunk): SelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "inner">>;
|
|
184
|
+
crossJoin<TTable extends Table>(table: TTable): SelectStatement<AppendToSelection<TSelection, TTable, TMode>, TMode extends "partial" ? "partial" : "multiple", AppendToNullabilityMap<TNullability, TTable, "cross">>;
|
|
185
|
+
where(chunk: Chunk): this & Record<"where", never>;
|
|
186
|
+
groupBy(...columns: Array<Chunk>): this & Record<"groupBy", never>;
|
|
187
|
+
having(chunk: Chunk): this & Record<"having", never>;
|
|
188
|
+
orderBy(...chunks: Array<Chunk>): this & Record<"orderBy", never>;
|
|
189
|
+
limit(count: number): this & Record<"limit", never>;
|
|
190
|
+
offset(count: number): this & Record<"offset", never>;
|
|
191
|
+
protected mapRow(row: Array<unknown>): Record<string, unknown>;
|
|
192
|
+
}
|
|
193
|
+
export declare class InsertStatement<T extends Table = Table> extends Statement<Array<InferSelectModel<T>>> {
|
|
194
|
+
protected $table: T;
|
|
195
|
+
constructor(session: Session, table: T);
|
|
196
|
+
values<This extends InsertStatement>(this: This, value: InferInsertModel<T> | Array<InferInsertModel<T>>): This & Record<"values", never>;
|
|
197
|
+
onConflictDoNothing<This extends InsertStatement>(this: This): This & Record<"onConflictDoNothing", never>;
|
|
198
|
+
returning<This extends InsertStatement>(this: This): This & Record<"returning", never>;
|
|
199
|
+
}
|
|
200
|
+
export declare class UpdateStatement<T extends Table = Table> extends Statement<Array<InferSelectModel<T>>> {
|
|
201
|
+
protected $table: T;
|
|
202
|
+
constructor(session: Session, table: T);
|
|
203
|
+
set<This extends UpdateStatement>(this: This, value: Partial<InferInsertModel<T>>): This & Record<"set", never>;
|
|
204
|
+
where<This extends UpdateStatement>(this: This, chunk: Chunk): This & Record<"where", never>;
|
|
205
|
+
returning<This extends UpdateStatement>(this: This): This & Record<"returning", never>;
|
|
206
|
+
}
|
|
207
|
+
export declare class DeleteStatement<T extends Table = Table> extends Statement<Array<InferSelectModel<T>>> {
|
|
208
|
+
protected $table: T;
|
|
209
|
+
constructor(session: Session, table: T);
|
|
210
|
+
where<This extends DeleteStatement>(this: This, chunk: Chunk): This & Record<"where", never>;
|
|
211
|
+
returning<This extends DeleteStatement>(this: This): This & Record<"returning", never>;
|
|
212
|
+
}
|
|
213
|
+
export declare abstract class PreparedQuery {
|
|
214
|
+
protected $query: Query;
|
|
215
|
+
constructor(query: Query);
|
|
216
|
+
getQuery(): Query<unknown>;
|
|
217
|
+
abstract run(parameters: Array<Primitive>): unknown;
|
|
218
|
+
abstract all(parameters: Array<Primitive>): unknown;
|
|
219
|
+
abstract get(parameters: Array<Primitive>): unknown;
|
|
220
|
+
abstract values(parameters: Array<Primitive>): unknown;
|
|
221
|
+
}
|
|
222
|
+
export declare abstract class Session {
|
|
223
|
+
run(query: Query): unknown;
|
|
224
|
+
all(query: Query): unknown;
|
|
225
|
+
get(query: Query): unknown;
|
|
226
|
+
values(query: Query): unknown;
|
|
227
|
+
abstract prepareQuery(query: Query): PreparedQuery;
|
|
228
|
+
}
|
|
229
|
+
export declare abstract class Migration {
|
|
230
|
+
abstract readonly $dialect: string;
|
|
231
|
+
toSql(changes: Array<MetaChange>, current: DatabaseMeta): Array<string>;
|
|
232
|
+
protected render({ changes }: MigrationContext): Array<string>;
|
|
233
|
+
diff(previous: DatabaseMeta | undefined, current: DatabaseMeta): MetaChange[];
|
|
234
|
+
protected diffValues<T>(before: Map<string, T>, after: Map<string, T>, factory: ChangeFactory<T>): MetaChange[];
|
|
235
|
+
protected splitDefinitions(definitions: Array<DefinitionMeta>): {
|
|
236
|
+
constraints: Map<string, ConstraintMeta>;
|
|
237
|
+
indexes: Map<string, IndexDefinitionMeta>;
|
|
238
|
+
};
|
|
239
|
+
protected definitionFingerprint(definition: DefinitionMeta): string;
|
|
240
|
+
protected renderChange(change: MetaChange): Array<string>;
|
|
241
|
+
protected toCreateTableChange(change: CreateTableChange, name?: string): Array<string>;
|
|
242
|
+
protected toDeleteTableChange(change: DeleteTableChange): Array<string>;
|
|
243
|
+
protected toCreateColumnChange(change: CreateColumnChange, inline?: boolean): Array<string>;
|
|
244
|
+
protected toUpdateColumnChange(change: UpdateColumnChange): Array<string>;
|
|
245
|
+
protected toDeleteColumnChange(change: DeleteColumnChange): Array<string>;
|
|
246
|
+
protected toCreateConstraintChange(change: CreateConstraintChange, inline?: boolean): Array<string>;
|
|
247
|
+
protected toDeleteConstraintChange(change: DeleteConstraintChange): Array<string>;
|
|
248
|
+
protected toCreateIndexChange(change: CreateIndexChange): Array<string>;
|
|
249
|
+
protected toDeleteIndexChange(change: DeleteIndexChange): Array<string>;
|
|
250
|
+
protected columnConstraints(column: ColumnMeta): ConstraintMeta[];
|
|
251
|
+
protected updateColumnConstraints(table: string, before: ColumnMeta, after: ColumnMeta): string[];
|
|
252
|
+
protected constraintName(table: string, constraint: ConstraintMeta): string;
|
|
253
|
+
protected indexName(table: string, index: IndexDefinitionMeta): string;
|
|
254
|
+
protected generatedName(parts: Array<string>): string;
|
|
255
|
+
protected hash(value: string): string;
|
|
256
|
+
protected quoteIdentifiers(values: Array<string>): string;
|
|
257
|
+
protected alterTable(table: string, value: string): string;
|
|
258
|
+
protected equals(left: unknown, right: unknown): boolean;
|
|
259
|
+
protected serializeLiteral(value: string | number | boolean | null): string;
|
|
260
|
+
protected abstract quoteIdentifier(value: string): string;
|
|
261
|
+
}
|
|
262
|
+
export declare abstract class Database<T extends Record<string, Table> = Record<string, Table>> {
|
|
263
|
+
readonly $schema: T;
|
|
264
|
+
readonly $session: Session;
|
|
265
|
+
abstract readonly $migration: Migration;
|
|
266
|
+
get $dialect(): string;
|
|
267
|
+
constructor(session: Session, schema: T);
|
|
268
|
+
toMeta(): DatabaseMeta;
|
|
269
|
+
abstract select<TValue extends Table | Record<string, Column>>(value: TValue): SelectStatement<TValue>;
|
|
270
|
+
abstract insert<TValue extends Table>(table: TValue): InsertStatement<TValue>;
|
|
271
|
+
abstract update<TValue extends Table>(table: TValue): UpdateStatement<TValue>;
|
|
272
|
+
abstract delete<TValue extends Table>(table: TValue): DeleteStatement<TValue>;
|
|
273
|
+
}
|
|
274
|
+
export declare abstract class Table<TName extends string = string, TColumns extends Record<string, Column> = Record<string, Column>> {
|
|
275
|
+
readonly $name: TName;
|
|
276
|
+
readonly $columns: TColumns;
|
|
277
|
+
readonly $definitions: Array<Definition>;
|
|
278
|
+
constructor(name: TName, columns: TColumns, definitions: Array<Definition>);
|
|
279
|
+
toMeta(): TableMeta;
|
|
280
|
+
toSql(): Sql<unknown>;
|
|
281
|
+
}
|
|
282
|
+
export declare abstract class Column<TDataType = unknown> {
|
|
283
|
+
$name: string;
|
|
284
|
+
$table: Table | undefined;
|
|
285
|
+
$notNull: boolean;
|
|
286
|
+
$primaryKey: boolean;
|
|
287
|
+
$unique: boolean;
|
|
288
|
+
$defaultValue: DefaultValue<TDataType>;
|
|
289
|
+
$references: References;
|
|
290
|
+
$onDelete: ReferentialAction | undefined;
|
|
291
|
+
$onUpdate: ReferentialAction | undefined;
|
|
292
|
+
constructor(name: string);
|
|
293
|
+
default<This extends Column>(this: This, defaultValue: DefaultValue<Data<This>>): This & Record<"default", never>;
|
|
294
|
+
notNull<This extends Column>(this: This): This & Record<"notNull", never>;
|
|
295
|
+
unique<This extends Column>(this: This): This & Record<"unique", never>;
|
|
296
|
+
primaryKey<This extends Column>(this: This): This & Record<"primaryKey", never>;
|
|
297
|
+
references<This extends Column>(this: This, references: References, actions?: ReferentialActions): This & Record<"references", never>;
|
|
298
|
+
fromDriverValue(value: unknown): TDataType;
|
|
299
|
+
toDriverValue(value: TDataType): Primitive;
|
|
300
|
+
toSql(): Sql<unknown>;
|
|
301
|
+
toSqlName(): Sql<unknown>;
|
|
302
|
+
toMeta(): ColumnMeta;
|
|
303
|
+
abstract toSqlType(): string;
|
|
304
|
+
}
|
|
305
|
+
export declare class UniqueConstraint {
|
|
306
|
+
$columns: Array<Column>;
|
|
307
|
+
constructor(...columns: Array<Column>);
|
|
308
|
+
on<This extends UniqueConstraint>(this: This, ...columns: Array<Column>): This & Record<"on", never>;
|
|
309
|
+
toMeta(): UniqueConstraintMeta;
|
|
310
|
+
}
|
|
311
|
+
export declare class CheckConstraint {
|
|
312
|
+
$value: Sql;
|
|
313
|
+
protected $query: Query;
|
|
314
|
+
constructor(value: Sql);
|
|
315
|
+
toMeta(): CheckConstraintMeta;
|
|
316
|
+
}
|
|
317
|
+
export declare class PrimaryKeyConstraint {
|
|
318
|
+
$columns: Array<Column>;
|
|
319
|
+
constructor(...columns: Array<Column>);
|
|
320
|
+
toMeta(): PrimaryKeyConstraintMeta;
|
|
321
|
+
}
|
|
322
|
+
export declare class ForeignKeyConstraint {
|
|
323
|
+
$columns: Array<Column>;
|
|
324
|
+
$foreignColumns: Array<Column>;
|
|
325
|
+
constructor(columns: Array<Column>, foreignColumns: Array<Column>);
|
|
326
|
+
toMeta(): ForeignKeyConstraintMeta;
|
|
327
|
+
}
|
|
328
|
+
export declare class Index {
|
|
329
|
+
$columns: Array<Column>;
|
|
330
|
+
constructor(...columns: Array<Column>);
|
|
331
|
+
on<This extends Index>(this: This, ...columns: Array<Column>): This & Record<"on", never>;
|
|
332
|
+
toMeta(): IndexMeta;
|
|
333
|
+
}
|
|
334
|
+
export declare class UniqueIndex {
|
|
335
|
+
$columns: Array<Column>;
|
|
336
|
+
constructor(...columns: Array<Column>);
|
|
337
|
+
on<This extends UniqueIndex>(this: This, ...columns: Array<Column>): This & Record<"on", never>;
|
|
338
|
+
toMeta(): UniqueIndexMeta;
|
|
339
|
+
}
|
|
340
|
+
export declare function toParameter(column: Column, value: unknown): Chunk;
|
|
341
|
+
export declare function combine<T>(chunks: Array<Chunk>, separator: string): Sql<T>;
|
|
342
|
+
export declare function sql<T>(tokens: TemplateStringsArray, ...values: Array<Chunk>): Sql<T>;
|
|
343
|
+
export declare function equals<T>(column: Column, right: Chunk): Sql<T>;
|
|
344
|
+
export declare function greater<T>(column: Column, right: Chunk): Sql<T>;
|
|
345
|
+
export declare function greaterEquals<T>(column: Column, right: Chunk): Sql<T>;
|
|
346
|
+
export declare function lower<T>(column: Column, right: Chunk): Sql<T>;
|
|
347
|
+
export declare function lowerEquals<T>(column: Column, right: Chunk): Sql<T>;
|
|
348
|
+
export declare function like<T>(column: Column, right: Chunk): Sql<T>;
|
|
349
|
+
export declare function contains<T>(column: Column, values: Array<Chunk>): Sql<T>;
|
|
350
|
+
export declare function nullish<T>(chunk: Chunk): Sql<T>;
|
|
351
|
+
export declare function not<T>(chunk: Chunk): Sql<T>;
|
|
352
|
+
export declare function exists<T>(chunk: Chunk): Sql<T>;
|
|
353
|
+
export declare function between<T>(column: Column, from: Chunk, to: Chunk): Sql<T>;
|
|
354
|
+
export declare function and<T>(...chunks: Array<Chunk>): Sql<T>;
|
|
355
|
+
export declare function or<T>(...chunks: Array<Chunk>): Sql<T>;
|
|
356
|
+
export declare function asc<T>(chunk: Chunk): Sql<T>;
|
|
357
|
+
export declare function desc<T>(chunk: Chunk): Sql<T>;
|
|
358
|
+
export declare function useStorage<TSource extends Source<(scope: Scope) => Database> = typeof import("#storage").default, TScope extends SourceScope<TSource> = SourceScope<TSource>>(scope: Scope, scopeName: TScope): { [TKey in SourceValue<TSource, TScope>]: ReturnType<Awaited<ReturnType<TSource[TScope][TKey]>>>; };
|
|
359
|
+
export declare const STORAGE_CONTEXT: import("revojs").Descriptor<Record<string, Record<string, Database<Record<string, Table<string, Record<string, Column<unknown>>>>>>>>;
|
|
360
|
+
export {};
|