rado 0.2.28 → 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 +13 -13
- package/dist/define/Column.js +3 -0
- 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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- 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
|
@@ -8,7 +8,7 @@ export declare enum ColumnType {
|
|
|
8
8
|
Boolean = "Boolean",
|
|
9
9
|
Json = "Json"
|
|
10
10
|
}
|
|
11
|
-
interface PartialColumnData {
|
|
11
|
+
export interface PartialColumnData {
|
|
12
12
|
type?: ColumnType;
|
|
13
13
|
name?: string;
|
|
14
14
|
nullable?: boolean;
|
|
@@ -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;
|
|
@@ -35,10 +35,10 @@ export declare namespace Column {
|
|
|
35
35
|
const IsPrimary: unique symbol;
|
|
36
36
|
function isColumn<T>(input: any): input is Column<T>;
|
|
37
37
|
}
|
|
38
|
-
interface ValueColumn<T> extends Expr<T> {
|
|
38
|
+
export interface ValueColumn<T> extends Expr<T> {
|
|
39
39
|
<X extends T = T>(): ValueColumn<T extends null ? X | null : X>;
|
|
40
40
|
}
|
|
41
|
-
declare class ValueColumn<T> extends Callable implements Column<T> {
|
|
41
|
+
export declare class ValueColumn<T> extends Callable implements Column<T> {
|
|
42
42
|
[Column.Type]: T;
|
|
43
43
|
[Column.Data]: PartialColumnData;
|
|
44
44
|
constructor(data: PartialColumnData);
|
|
@@ -52,13 +52,13 @@ declare class ValueColumn<T> extends Callable implements Column<T> {
|
|
|
52
52
|
export declare class OptionalColumn<T> extends ValueColumn<T> {
|
|
53
53
|
[Column.IsOptional]: true;
|
|
54
54
|
}
|
|
55
|
-
export declare class PrimaryColumn<T, K> extends ValueColumn<PrimaryKey<T, K>> {
|
|
55
|
+
export declare class PrimaryColumn<T, K> extends ValueColumn<string extends K ? T : PrimaryKey<T, K>> {
|
|
56
56
|
[Column.IsPrimary]: K;
|
|
57
57
|
}
|
|
58
|
-
interface ObjectColumn<T> {
|
|
58
|
+
export interface ObjectColumn<T> {
|
|
59
59
|
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<X>;
|
|
60
60
|
}
|
|
61
|
-
declare class ObjectColumn<T> extends Callable implements Column<T> {
|
|
61
|
+
export declare class ObjectColumn<T> extends Callable implements Column<T> {
|
|
62
62
|
[Column.Type]: T;
|
|
63
63
|
[Column.Data]: PartialColumnData;
|
|
64
64
|
constructor(data: PartialColumnData);
|
|
@@ -69,14 +69,14 @@ declare class ObjectColumn<T> extends Callable implements Column<T> {
|
|
|
69
69
|
export declare class OptionalObjectColumn<T> extends ObjectColumn<T> {
|
|
70
70
|
[Column.IsOptional]: true;
|
|
71
71
|
}
|
|
72
|
-
export type PrimaryKey<T, K> =
|
|
72
|
+
export type PrimaryKey<T, K> = T & {
|
|
73
73
|
[Column.IsPrimary]: K;
|
|
74
74
|
};
|
|
75
75
|
type DefaultValue<T> = EV<T> | (() => EV<T>);
|
|
76
|
-
interface UnTyped {
|
|
76
|
+
export interface UnTyped {
|
|
77
77
|
(name: string): UnTyped;
|
|
78
78
|
}
|
|
79
|
-
declare class UnTyped extends Callable {
|
|
79
|
+
export declare class UnTyped extends Callable {
|
|
80
80
|
[Column.Data]: PartialColumnData;
|
|
81
81
|
constructor(data?: PartialColumnData);
|
|
82
82
|
get nullable(): NullableUnTyped;
|
|
@@ -89,7 +89,7 @@ declare class UnTyped extends Callable {
|
|
|
89
89
|
get object(): ObjectColumn<{}>;
|
|
90
90
|
get array(): ValueColumn<any[]>;
|
|
91
91
|
}
|
|
92
|
-
declare class NullableUnTyped {
|
|
92
|
+
export declare class NullableUnTyped {
|
|
93
93
|
[Column.Data]: PartialColumnData;
|
|
94
94
|
get unique(): UnTyped;
|
|
95
95
|
get string(): ValueColumn<string | null>;
|
package/dist/define/Column.js
CHANGED
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/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type { Selection } from './define/Selection';
|
|
|
13
13
|
export * from './define/Sql';
|
|
14
14
|
export * from './define/Table';
|
|
15
15
|
export * from './define/Target';
|
|
16
|
+
export * from './define/VirtualTable';
|
|
16
17
|
export type { Driver } from './lib/Driver';
|
|
17
18
|
export type { FormatContext, Formatter } from './lib/Formatter';
|
|
18
19
|
export type { Sanitizer } from './lib/Sanitizer';
|
package/dist/index.js
CHANGED
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);
|