@rwillians/qx 0.1.20 → 0.2.0
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/cjs/adapter.js +27 -0
- package/dist/cjs/bun-sqlite.js +545 -0
- package/dist/cjs/console-logger.js +135 -0
- package/dist/cjs/experimental-migrations.js +90 -0
- package/dist/cjs/index.js +718 -0
- package/dist/cjs/standard-schema.js +239 -0
- package/dist/cjs/utils.js +92 -0
- package/dist/esm/adapter.js +23 -0
- package/dist/esm/bun-sqlite.js +544 -0
- package/dist/esm/console-logger.js +132 -0
- package/dist/esm/experimental-migrations.js +86 -0
- package/dist/esm/index.js +711 -0
- package/dist/esm/standard-schema.js +235 -0
- package/dist/esm/utils.js +79 -0
- package/dist/types/adapter.d.ts +16 -0
- package/dist/types/bun-sqlite.d.ts +65 -0
- package/dist/types/console-logger.d.ts +21 -0
- package/dist/types/experimental-migrations.d.ts +63 -0
- package/dist/types/index.d.ts +1272 -0
- package/dist/types/standard-schema.d.ts +189 -0
- package/dist/types/utils.d.ts +79 -0
- package/package.json +4 -3
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
2
|
+
// STANDARD SCHEMA SPEC //
|
|
3
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
4
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
5
|
+
// STANDARD SCHEMA API //
|
|
6
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
7
|
+
/**
|
|
8
|
+
* @public The Standard Schema interface.
|
|
9
|
+
* @since 0.1.0
|
|
10
|
+
* @version 1
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
/**
|
|
14
|
+
* @public Use any standard schema to parse a value.
|
|
15
|
+
* @since 0.1.0
|
|
16
|
+
* @version 1
|
|
17
|
+
*/
|
|
18
|
+
export const parse = (schema, value) => {
|
|
19
|
+
const parsed = schema['~standard'].validate(value);
|
|
20
|
+
if (parsed instanceof Promise) {
|
|
21
|
+
throw new Error('async standard schema validators are not supported');
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
};
|
|
25
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
26
|
+
// UTILS //
|
|
27
|
+
// // // // // // // // // // // // // // // // // // // // // // // //
|
|
28
|
+
const prependPath = (path) => (issue) => ({
|
|
29
|
+
...issue,
|
|
30
|
+
path: [path, ...(issue.path ?? [])],
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* @public Defines an array of a given standard schema.
|
|
34
|
+
* @since 0.1.0
|
|
35
|
+
* @version 1
|
|
36
|
+
*/
|
|
37
|
+
export const array = (schema) => ({
|
|
38
|
+
'~standard': {
|
|
39
|
+
version: 1,
|
|
40
|
+
vendor: 'qx',
|
|
41
|
+
validate: (input) => {
|
|
42
|
+
if (!Array.isArray(input)) {
|
|
43
|
+
return { issues: [{ message: 'must be an array' }] };
|
|
44
|
+
}
|
|
45
|
+
const issues = [];
|
|
46
|
+
const value = [];
|
|
47
|
+
for (let i = 0; i < input.length; i++) {
|
|
48
|
+
const parsed = parse(schema, input[i]);
|
|
49
|
+
parsed.issues
|
|
50
|
+
? issues.push(...parsed.issues.map(prependPath(i)))
|
|
51
|
+
: value.push(parsed.value);
|
|
52
|
+
}
|
|
53
|
+
return issues.length > 0
|
|
54
|
+
? { issues }
|
|
55
|
+
: { value: value };
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* @public Defines a standard schema for boolean values.
|
|
61
|
+
* @since 0.1.0
|
|
62
|
+
* @version 1
|
|
63
|
+
*/
|
|
64
|
+
export const boolean = () => ({
|
|
65
|
+
'~standard': {
|
|
66
|
+
version: 1,
|
|
67
|
+
vendor: 'qx',
|
|
68
|
+
validate: (input) => typeof input !== 'boolean'
|
|
69
|
+
? { issues: [{ message: 'must be a boolean' }] }
|
|
70
|
+
: { value: input },
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* @public Defines a standard schema for Date values that can be
|
|
75
|
+
* coerced from ISO 8601 strings or epoch timestamps in
|
|
76
|
+
* milliseconds.
|
|
77
|
+
* @since 0.1.0
|
|
78
|
+
* @version 1
|
|
79
|
+
*/
|
|
80
|
+
export const date = () => ({
|
|
81
|
+
'~standard': {
|
|
82
|
+
version: 1,
|
|
83
|
+
vendor: 'qx',
|
|
84
|
+
validate: (input) => {
|
|
85
|
+
if (input instanceof Date)
|
|
86
|
+
return isNaN(input.getTime())
|
|
87
|
+
? { issues: [{ message: 'must be a valid date' }] }
|
|
88
|
+
: { value: input };
|
|
89
|
+
if (typeof input !== 'string' &&
|
|
90
|
+
typeof input !== 'number')
|
|
91
|
+
return { issues: [{ message: 'must be a valid ISO 8601 string or epoch timestamp in milliseconds' }] };
|
|
92
|
+
const date = new Date(input);
|
|
93
|
+
if (isNaN(date.getTime()))
|
|
94
|
+
return { issues: [{ message: 'must be a valid ISO 8601 string or epoch timestamp in milliseconds' }] };
|
|
95
|
+
return { value: date };
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* @public Defines a standard schema that validates instances of a
|
|
101
|
+
* given class.
|
|
102
|
+
* @since 0.1.0
|
|
103
|
+
* @version 1
|
|
104
|
+
*/
|
|
105
|
+
export const instanceOf = (ctor) => ({
|
|
106
|
+
'~standard': {
|
|
107
|
+
version: 1,
|
|
108
|
+
vendor: 'qx',
|
|
109
|
+
validate: (input) => !(input instanceof ctor)
|
|
110
|
+
? { issues: [{ message: `must be an instance of ${ctor.name}` }] }
|
|
111
|
+
: { value: input },
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
/**
|
|
115
|
+
* @public Defines a standard schema for integers with optional min and max constraints.
|
|
116
|
+
* @since 0.1.0
|
|
117
|
+
* @version 1
|
|
118
|
+
*/
|
|
119
|
+
export const integer = ({ min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER } = {}) => ({
|
|
120
|
+
'~standard': {
|
|
121
|
+
version: 1,
|
|
122
|
+
vendor: 'qx',
|
|
123
|
+
validate: (input) => {
|
|
124
|
+
if (typeof input !== 'number')
|
|
125
|
+
return { issues: [{ message: 'must be a integer' }] };
|
|
126
|
+
if (Number.isNaN(input) || !Number.isFinite(input))
|
|
127
|
+
return { issues: [{ message: 'must be a integer' }] };
|
|
128
|
+
if (!Number.isInteger(input))
|
|
129
|
+
return { issues: [{ message: 'must be a integer' }] };
|
|
130
|
+
if (input < min)
|
|
131
|
+
return { issues: [{ message: `must be greater than or equal to ${min}` }] };
|
|
132
|
+
if (input > max)
|
|
133
|
+
return { issues: [{ message: `must be less than or equal to ${max}` }] };
|
|
134
|
+
return { value: input };
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
/**
|
|
139
|
+
* @public Makes any standard schema accepts `null` as a valid value.
|
|
140
|
+
* @since 0.1.0
|
|
141
|
+
* @version 1
|
|
142
|
+
*/
|
|
143
|
+
export const nullable = (schema) => ({
|
|
144
|
+
'~standard': {
|
|
145
|
+
version: 1,
|
|
146
|
+
vendor: 'qx',
|
|
147
|
+
validate: (value) => value === null
|
|
148
|
+
? { value }
|
|
149
|
+
: parse(schema, value),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* @public Defines a standard schema for numbers with optional min
|
|
154
|
+
* and max constraints.
|
|
155
|
+
* @since 0.1.0
|
|
156
|
+
* @version 1
|
|
157
|
+
*/
|
|
158
|
+
export const number = ({ min = Number.MIN_VALUE, max = Number.MAX_VALUE } = {}) => ({
|
|
159
|
+
'~standard': {
|
|
160
|
+
version: 1,
|
|
161
|
+
vendor: 'qx',
|
|
162
|
+
validate: (input) => {
|
|
163
|
+
if (typeof input !== 'number')
|
|
164
|
+
return { issues: [{ message: 'must be a number' }] };
|
|
165
|
+
if (Number.isNaN(input) || !Number.isFinite(input))
|
|
166
|
+
return { issues: [{ message: 'must be a number' }] };
|
|
167
|
+
if (input < min)
|
|
168
|
+
return { issues: [{ message: `must be greater than or equal to ${min}` }] };
|
|
169
|
+
if (input > max)
|
|
170
|
+
return { issues: [{ message: `must be less than or equal to ${max}` }] };
|
|
171
|
+
return { value: input };
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* @public Defines an object schema that does not allow extra fields.
|
|
177
|
+
* @since 0.1.0
|
|
178
|
+
* @version 1
|
|
179
|
+
*/
|
|
180
|
+
export const strictObject = (shape) => ({
|
|
181
|
+
'~standard': {
|
|
182
|
+
version: 1,
|
|
183
|
+
vendor: 'qx',
|
|
184
|
+
validate: (input) => {
|
|
185
|
+
if (typeof input !== 'object' || input === null) {
|
|
186
|
+
return { issues: [{ message: 'must be an object' }] };
|
|
187
|
+
}
|
|
188
|
+
const issues = [];
|
|
189
|
+
const inputKeys = new Set(Object.keys(input));
|
|
190
|
+
const shapeKeys = new Set(Object.keys(shape));
|
|
191
|
+
// one issue for each key of `input` that doesn't exist in `shape`
|
|
192
|
+
for (const key of inputKeys.difference(shapeKeys)) {
|
|
193
|
+
issues.push({ path: [key], message: 'unknown field' });
|
|
194
|
+
}
|
|
195
|
+
// one issue for each key of `shape` that doesn't exist in `input`
|
|
196
|
+
for (const key of shapeKeys.difference(inputKeys)) {
|
|
197
|
+
issues.push({ path: [key], message: 'is required' });
|
|
198
|
+
}
|
|
199
|
+
const record = {};
|
|
200
|
+
for (const [key, value] of Object.entries(input)) {
|
|
201
|
+
const parsed = shape[key]['~standard'].validate(value);
|
|
202
|
+
if (parsed instanceof Promise) {
|
|
203
|
+
throw new Error('async validators are not supported');
|
|
204
|
+
}
|
|
205
|
+
parsed.issues
|
|
206
|
+
? issues.push(...parsed.issues.map(prependPath(key)))
|
|
207
|
+
: record[key] = parsed.value;
|
|
208
|
+
}
|
|
209
|
+
return issues.length > 0
|
|
210
|
+
? { issues }
|
|
211
|
+
: { value: record };
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
/**
|
|
216
|
+
* @public Defines a standard schema for strings with optional min
|
|
217
|
+
* and max length constraints.
|
|
218
|
+
* @since 0.1.0
|
|
219
|
+
* @version 1
|
|
220
|
+
*/
|
|
221
|
+
export const string = ({ min, max } = {}) => ({
|
|
222
|
+
'~standard': {
|
|
223
|
+
version: 1,
|
|
224
|
+
vendor: 'qx',
|
|
225
|
+
validate: (input) => {
|
|
226
|
+
if (typeof input !== 'string')
|
|
227
|
+
return { issues: [{ message: 'must be a string' }] };
|
|
228
|
+
if (min !== undefined && input.length < min)
|
|
229
|
+
return { issues: [{ message: `must be at least ${min} characters long` }] };
|
|
230
|
+
if (max !== undefined && input.length > max)
|
|
231
|
+
return { issues: [{ message: `must be at most ${max} characters long` }] };
|
|
232
|
+
return { value: input };
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private Converts a snake_case string to camelCase.
|
|
3
|
+
* @since 0.1.0
|
|
4
|
+
* @version 2
|
|
5
|
+
*/
|
|
6
|
+
export const camelCase = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
7
|
+
/**
|
|
8
|
+
* @private Same as {@link Object.prototype.entries} but with better
|
|
9
|
+
* types.
|
|
10
|
+
* @since 0.1.17
|
|
11
|
+
* @version 1
|
|
12
|
+
*/
|
|
13
|
+
export const entries = (obj) => Object.entries(obj);
|
|
14
|
+
/**
|
|
15
|
+
* @private Simplified check for plain objects.
|
|
16
|
+
* @since 0.1.0
|
|
17
|
+
* @version 1
|
|
18
|
+
*/
|
|
19
|
+
export const isPlainObject = (value) => {
|
|
20
|
+
if (typeof value !== 'object' || value === null)
|
|
21
|
+
return false;
|
|
22
|
+
let proto = Object.getPrototypeOf(value);
|
|
23
|
+
if (proto === null)
|
|
24
|
+
return true;
|
|
25
|
+
return proto === Object.prototype;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @private Same as {@link Object.prototype.keys} but with better
|
|
29
|
+
* types.
|
|
30
|
+
* @since 0.1.17
|
|
31
|
+
* @version 1
|
|
32
|
+
*/
|
|
33
|
+
export const keys = (obj) => Object.keys(obj);
|
|
34
|
+
/**
|
|
35
|
+
* @private Throws an error if the given number is greater than the
|
|
36
|
+
* specified maximum.
|
|
37
|
+
* @since 0.1.0
|
|
38
|
+
* @version 1
|
|
39
|
+
*/
|
|
40
|
+
export const lte = (n, max) => {
|
|
41
|
+
if (n > max)
|
|
42
|
+
throw new Error(`Must be at most ${max}, got ${n}`);
|
|
43
|
+
return n;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @public Maps over the keys of an object.
|
|
47
|
+
* @since 0.1.0
|
|
48
|
+
* @version 1
|
|
49
|
+
*/
|
|
50
|
+
export const mapKeys = (obj, fn) => Object.fromEntries(entries(obj).map(([key, value]) => [fn(key), value]));
|
|
51
|
+
/**
|
|
52
|
+
* @private Maps over the values of an object.
|
|
53
|
+
* @since 0.1.0
|
|
54
|
+
* @version 1
|
|
55
|
+
*/
|
|
56
|
+
export const mapValues = (obj, fn) => Object.fromEntries(entries(obj).map(([key, value]) => [key, fn(value, key)]));
|
|
57
|
+
/**
|
|
58
|
+
* @private Resolves the given value or function to a value.
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
* @version 1
|
|
61
|
+
*/
|
|
62
|
+
export const resolve = (value) => typeof value === 'function'
|
|
63
|
+
? value()
|
|
64
|
+
: value;
|
|
65
|
+
/**
|
|
66
|
+
* @private Converts a camelCase string to snake_case.
|
|
67
|
+
* @since 0.1.0
|
|
68
|
+
* @version 1
|
|
69
|
+
*/
|
|
70
|
+
export const snakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
71
|
+
/**
|
|
72
|
+
* @public Wraps the given value in an array, unless it's already an
|
|
73
|
+
* array.
|
|
74
|
+
* @since 0.1.0
|
|
75
|
+
* @version 1
|
|
76
|
+
*/
|
|
77
|
+
export const wrap = (value) => Array.isArray(value)
|
|
78
|
+
? value
|
|
79
|
+
: [value];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ILogger } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* @public Wraps a function call that executes DDL with logging
|
|
4
|
+
* capabilities.
|
|
5
|
+
*
|
|
6
|
+
* A `debug` log is emitted before the function is executed,
|
|
7
|
+
* and an `error` log if the function throws an error. After
|
|
8
|
+
* logging, the error is re-thrown.
|
|
9
|
+
* @since 0.1.17
|
|
10
|
+
* @version 1
|
|
11
|
+
*/
|
|
12
|
+
export declare const withLoggedQuery: <T>(logger: ILogger | ILogger[], data: {
|
|
13
|
+
sql: string;
|
|
14
|
+
params: any[];
|
|
15
|
+
}, fn: (sql: string, params: any[]) => Promise<T> | T) => Promise<T>;
|
|
16
|
+
export { type CodecsRegistry, type Column, type CreateTableStatement, type DDL, type DeleteStatement, type Expr, type ExprAnd, type ExprBinaryOp, type ExprLiteral, type ExprNot, type ExprOr, type IDatabase, type ILogger, type InsertStatement, type Join, type OrderDirection, type PrimitiveToNativeTypeFactory, type SelectStatement, is, } from './index';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Database } from 'bun:sqlite';
|
|
2
|
+
import { type CreateTableStatement, type DeleteStatement, type IDatabase, type ILogger, type InsertStatement, type SelectStatement } from './adapter';
|
|
3
|
+
/**
|
|
4
|
+
* @private Bun SQLite database adapter implementation.
|
|
5
|
+
* @since 0.1.0
|
|
6
|
+
* @version 1
|
|
7
|
+
*/
|
|
8
|
+
declare class BunSQLite implements IDatabase {
|
|
9
|
+
private conn;
|
|
10
|
+
private loggers;
|
|
11
|
+
constructor(conn: Database, loggers?: ILogger[]);
|
|
12
|
+
/**
|
|
13
|
+
* @public Attaches a logger to the database instance.
|
|
14
|
+
* @since 0.1.0
|
|
15
|
+
* @version 1
|
|
16
|
+
*/
|
|
17
|
+
attachLogger(logger: ILogger): this;
|
|
18
|
+
/**
|
|
19
|
+
* @public Executes a delete statement.
|
|
20
|
+
* @since 0.1.22
|
|
21
|
+
* @version 1
|
|
22
|
+
*/
|
|
23
|
+
delete(op: DeleteStatement): Promise<number>;
|
|
24
|
+
/**
|
|
25
|
+
* @public Executes a create table statement.
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
* @version 1
|
|
28
|
+
*/
|
|
29
|
+
createTable(op: CreateTableStatement): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* @public Executes an insert statement.
|
|
32
|
+
* @since 0.1.0
|
|
33
|
+
* @version 1
|
|
34
|
+
*/
|
|
35
|
+
insert(op: InsertStatement): Promise<{
|
|
36
|
+
[k: string]: any;
|
|
37
|
+
}[]>;
|
|
38
|
+
/**
|
|
39
|
+
* @public Executes a select statement.
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @version 1
|
|
42
|
+
*/
|
|
43
|
+
query(op: SelectStatement): Promise<{
|
|
44
|
+
[k: string]: any;
|
|
45
|
+
}[]>;
|
|
46
|
+
/**
|
|
47
|
+
* @public Executes a function within a transaction.
|
|
48
|
+
* @since 0.1.10
|
|
49
|
+
* @version 1
|
|
50
|
+
*/
|
|
51
|
+
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @public Creates a connection to the database.
|
|
55
|
+
* @since 0.1.0
|
|
56
|
+
* @version 1
|
|
57
|
+
*/
|
|
58
|
+
declare const connect: (...args: ConstructorParameters<typeof Database>) => BunSQLite;
|
|
59
|
+
/**
|
|
60
|
+
* @public Creates a connection to an in-memory database.
|
|
61
|
+
* @since 0.1.12
|
|
62
|
+
* @version 2
|
|
63
|
+
*/
|
|
64
|
+
declare const inmemory: () => BunSQLite;
|
|
65
|
+
export { connect, inmemory, };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ILogger } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* @public Creates a basic console logger that pretty-prints queries.
|
|
4
|
+
*
|
|
5
|
+
* Pretty printing is enabled by default but you can disable
|
|
6
|
+
* it to print plain-text instead (no ASCII styling), just
|
|
7
|
+
* set the option `pretty` to `false`.
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
* @version 3
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createConsoleLogger } from '@rwillians/qx/console-logger';
|
|
14
|
+
*
|
|
15
|
+
* const prettyLogger = createConsoleLogger();
|
|
16
|
+
* const plainLogger = createConsoleLogger({ pretty: false });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const createConsoleLogger: (opts?: {
|
|
20
|
+
pretty: boolean;
|
|
21
|
+
}) => ILogger;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type IDatabase, type Table } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* @public Create statement builder.
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
* @version 1
|
|
6
|
+
*/
|
|
7
|
+
export declare const create: {
|
|
8
|
+
/**
|
|
9
|
+
* @public Prepares a create table statement.
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
* @version 1
|
|
12
|
+
*/
|
|
13
|
+
table: <T extends Table, S extends {
|
|
14
|
+
ifNotExists?: true;
|
|
15
|
+
unlogged?: true;
|
|
16
|
+
}>(table: T, options?: S) => {
|
|
17
|
+
/**
|
|
18
|
+
* @public Executes the create table statement onto the given
|
|
19
|
+
* database.
|
|
20
|
+
* @since 0.1.0
|
|
21
|
+
* @version 1
|
|
22
|
+
*/
|
|
23
|
+
onto: (db: IDatabase) => Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @private Defines the type for a migration function.
|
|
28
|
+
* @since 0.1.6
|
|
29
|
+
* @version 1
|
|
30
|
+
*/
|
|
31
|
+
type Migration = (db: IDatabase) => Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* @public Defines a set of migrations to be executed against a
|
|
34
|
+
* database.
|
|
35
|
+
* @since 0.1.6
|
|
36
|
+
* @version 2
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // src/db/migrations.ts
|
|
41
|
+
* import { create, defineMigrations } from '@rwillians/qx/experimental-migrations';
|
|
42
|
+
* import { users } from './users';
|
|
43
|
+
* import { profiles } from './profiles';
|
|
44
|
+
*
|
|
45
|
+
* export const migrate = defineMigrations({
|
|
46
|
+
* '0001': async (db) => {
|
|
47
|
+
* await create.table(users).onto(db);
|
|
48
|
+
* },
|
|
49
|
+
* '0002': async (db) => {
|
|
50
|
+
* await create.table(profiles).onto(db);
|
|
51
|
+
* },
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // src/index.ts
|
|
55
|
+
* import * as sqlite from '@rwillians/qx/bun-sqlite';
|
|
56
|
+
* import { migrate } from './db/migrations';
|
|
57
|
+
*
|
|
58
|
+
* const db = sqlite.connect('./db.sqlite');
|
|
59
|
+
* await migrate(db)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const defineMigrations: (migs: Record<string, Migration>) => (db: IDatabase) => Promise<void>;
|
|
63
|
+
export {};
|