rado 0.2.29 → 0.2.30
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/define/Column.d.ts +3 -3
- package/dist/define/Expr.d.ts +3 -0
- package/dist/define/Expr.js +5 -1
- package/dist/define/Table.d.ts +14 -10
- package/dist/define/query/Select.d.ts +1 -1
- package/dist/define/query/TableSelect.d.ts +1 -1
- package/dist/lib/Driver.js +2 -2
- package/dist/lib/Formatter.js +5 -3
- package/package.json +1 -1
package/dist/define/Column.d.ts
CHANGED
|
@@ -23,9 +23,9 @@ export interface ColumnData extends PartialColumnData {
|
|
|
23
23
|
type: ColumnType;
|
|
24
24
|
name: string;
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
[Column.Type]: T;
|
|
28
|
-
[Column.Data]: PartialColumnData;
|
|
26
|
+
export declare class Column<T> {
|
|
27
|
+
get [Column.Type](): T;
|
|
28
|
+
get [Column.Data](): PartialColumnData;
|
|
29
29
|
}
|
|
30
30
|
export declare namespace Column {
|
|
31
31
|
const Data: unique symbol;
|
package/dist/define/Expr.d.ts
CHANGED
|
@@ -171,5 +171,8 @@ export declare namespace Expr {
|
|
|
171
171
|
function create<T>(input: EV<T>): Expr<T>;
|
|
172
172
|
function and(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
173
173
|
function or(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
174
|
+
function hasExpr<T>(input: any): input is {
|
|
175
|
+
[Expr.ToExpr](): Expr<T>;
|
|
176
|
+
};
|
|
174
177
|
function isExpr<T>(input: any): input is Expr<T>;
|
|
175
178
|
}
|
package/dist/define/Expr.js
CHANGED
|
@@ -135,7 +135,7 @@ var ExprData;
|
|
|
135
135
|
function create(input) {
|
|
136
136
|
if (input === null || input === void 0)
|
|
137
137
|
return new ExprData2.Param(new ParamData.Value(null));
|
|
138
|
-
if (
|
|
138
|
+
if (Expr.hasExpr(input))
|
|
139
139
|
input = input[Expr.ToExpr]();
|
|
140
140
|
if (Expr.isExpr(input))
|
|
141
141
|
return input[Expr.Data];
|
|
@@ -411,6 +411,10 @@ var Expr = class {
|
|
|
411
411
|
return conditions.map(create).reduce((condition, expr) => condition.or(expr), value(false));
|
|
412
412
|
}
|
|
413
413
|
Expr2.or = or;
|
|
414
|
+
function hasExpr(input) {
|
|
415
|
+
return input && (typeof input === "function" || typeof input === "object") && input[Expr2.ToExpr];
|
|
416
|
+
}
|
|
417
|
+
Expr2.hasExpr = hasExpr;
|
|
414
418
|
function isExpr(input) {
|
|
415
419
|
return input !== null && (typeof input === "object" || typeof input === "function") && input[Expr2.IsExpr];
|
|
416
420
|
}
|
package/dist/define/Table.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { EV, Expr } from './Expr';
|
|
|
4
4
|
import type { Fields } from './Fields';
|
|
5
5
|
import { Index, IndexData } from './Index';
|
|
6
6
|
import type { Selection } from './Selection';
|
|
7
|
+
import { SelectSingle } from './query/Select';
|
|
7
8
|
import { TableSelect } from './query/TableSelect';
|
|
8
9
|
interface TableDefinition {
|
|
9
10
|
}
|
|
@@ -28,18 +29,21 @@ export declare class TableInstance<Definition> {
|
|
|
28
29
|
get [Table.Data](): TableData;
|
|
29
30
|
}
|
|
30
31
|
export type Table<Definition> = Definition & TableInstance<Definition>;
|
|
32
|
+
type TableOf<Row> = Table<{
|
|
33
|
+
[K in keyof Row as K extends string ? K : never]: Column<Row[K]> & Fields<Row[K]>;
|
|
34
|
+
}>;
|
|
35
|
+
type RowOf<Definition> = {
|
|
36
|
+
[K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? T : never;
|
|
37
|
+
};
|
|
38
|
+
type UpdateOf<Definition> = Partial<{
|
|
39
|
+
[K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? EV<T> | SelectSingle<T> : never;
|
|
40
|
+
}>;
|
|
31
41
|
export declare namespace Table {
|
|
32
42
|
export const Data: unique symbol;
|
|
33
43
|
export const Meta: unique symbol;
|
|
34
|
-
export type Of<Row> =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
export type Select<Definition> = {
|
|
38
|
-
[K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? T : never;
|
|
39
|
-
};
|
|
40
|
-
export type Update<Definition> = Partial<{
|
|
41
|
-
[K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? EV<T> : never;
|
|
42
|
-
}>;
|
|
44
|
+
export type Of<Row> = TableOf<Row>;
|
|
45
|
+
export type Select<Definition> = RowOf<Definition>;
|
|
46
|
+
export type Update<Definition> = UpdateOf<Definition>;
|
|
43
47
|
type IsOptional<K> = K extends PrimaryColumn<any, any> ? true : K extends OptionalColumn<any> ? true : K extends Column<infer V> ? null extends V ? true : false : never;
|
|
44
48
|
export type Insert<Definition> = {
|
|
45
49
|
[K in keyof Definition as true extends IsOptional<Definition[K]> ? K : never]?: Definition[K] extends Column<infer V> ? EV<V> : never;
|
|
@@ -54,7 +58,7 @@ export interface TableMeta {
|
|
|
54
58
|
interface Define<T> {
|
|
55
59
|
new (): T;
|
|
56
60
|
}
|
|
57
|
-
export type table<T> = T extends Table<infer D> ?
|
|
61
|
+
export type table<T> = Table.Select<T extends Table<infer D> ? D : T>;
|
|
58
62
|
export declare function createTable<Definition>(data: TableData): Table<Definition>;
|
|
59
63
|
export declare function table<T extends {}>(define: Record<string, T | Define<T>>): Table<T>;
|
|
60
64
|
export declare namespace table {
|
|
@@ -15,7 +15,7 @@ export declare class SelectMultiple<Row> extends Union<Row> {
|
|
|
15
15
|
count(): SelectSingle<number>;
|
|
16
16
|
orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<Row>;
|
|
17
17
|
groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<Row>;
|
|
18
|
-
maybeFirst(): SelectSingle<Row |
|
|
18
|
+
maybeFirst(): SelectSingle<Row | null>;
|
|
19
19
|
first(): SelectSingle<Row>;
|
|
20
20
|
where(...where: Array<EV<boolean>>): SelectMultiple<Row>;
|
|
21
21
|
take(limit: number | undefined): SelectMultiple<Row>;
|
|
@@ -13,7 +13,7 @@ export declare class TableSelect<Definition> extends SelectMultiple<Table.Select
|
|
|
13
13
|
as(alias: string): Table<Definition>;
|
|
14
14
|
create(): CreateTable;
|
|
15
15
|
insertSelect(query: SelectMultiple<Table.Insert<Definition>>): Inserted;
|
|
16
|
-
insertOne(record: Table.Insert<Definition>): Query<
|
|
16
|
+
insertOne(record: Table.Insert<Definition>): Query<{ [K in keyof Definition as Definition[K] extends import("../Column").Column<any> ? K : never]: Definition[K] extends import("../Column").Column<infer T> ? T : never; }>;
|
|
17
17
|
insertAll(data: Array<Table.Insert<Definition>>): Inserted;
|
|
18
18
|
set(data: Table.Update<Definition>): Update<Definition>;
|
|
19
19
|
delete(): Delete;
|
package/dist/lib/Driver.js
CHANGED
|
@@ -99,7 +99,7 @@ var SyncDriver = class extends DriverBase {
|
|
|
99
99
|
const row = res[0];
|
|
100
100
|
if (query.validate && row === void 0)
|
|
101
101
|
throw new Error("No row found");
|
|
102
|
-
return row;
|
|
102
|
+
return row ?? null;
|
|
103
103
|
}
|
|
104
104
|
return res;
|
|
105
105
|
} else if (query.type === QueryType.Raw) {
|
|
@@ -215,7 +215,7 @@ var AsyncDriver = class extends DriverBase {
|
|
|
215
215
|
const row = res[0];
|
|
216
216
|
if (query.validate && row === void 0)
|
|
217
217
|
throw new Error("No row found");
|
|
218
|
-
return row;
|
|
218
|
+
return row ?? null;
|
|
219
219
|
}
|
|
220
220
|
return res;
|
|
221
221
|
} else if (query.type === QueryType.Raw) {
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -165,11 +165,13 @@ var Formatter = class {
|
|
|
165
165
|
const keys = Object.keys(data).filter((key) => query.table.columns[key]);
|
|
166
166
|
for (const key of stmt.separate(keys)) {
|
|
167
167
|
stmt.identifier(key).add("=").space();
|
|
168
|
-
|
|
169
|
-
if (Expr.
|
|
168
|
+
let input = data[key];
|
|
169
|
+
if (Expr.hasExpr(input))
|
|
170
|
+
input = input[Expr.ToExpr]();
|
|
171
|
+
if (Expr.isExpr(input))
|
|
170
172
|
this.formatExprJson(ctx, ExprData.create(data[key]));
|
|
171
173
|
else
|
|
172
|
-
this.formatValue({ ...ctx, formatAsInsert: true },
|
|
174
|
+
this.formatValue({ ...ctx, formatAsInsert: true }, input);
|
|
173
175
|
}
|
|
174
176
|
this.formatWhere(ctx, query.where);
|
|
175
177
|
this.formatLimit(ctx, query);
|