rado 0.1.13 → 0.1.15
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/lib/Formatter.js +3 -4
- package/dist/lib/Index.d.ts +2 -0
- package/dist/lib/Index.js +3 -0
- package/dist/lib/Table.d.ts +8 -2
- package/dist/lib/Table.js +22 -0
- package/package.json +1 -1
package/dist/lib/Formatter.js
CHANGED
|
@@ -84,9 +84,8 @@ var Formatter = class {
|
|
|
84
84
|
}
|
|
85
85
|
formatInsert(query, ctx) {
|
|
86
86
|
const columns = Object.values(query.into.columns);
|
|
87
|
-
return raw("insert into").
|
|
88
|
-
|
|
89
|
-
...columns.map((column) => this.formatString(column.name))
|
|
87
|
+
return raw("insert into").addIdentifier(query.into.name).addIf(query.into.alias, () => raw("as").addIdentifier(query.into.alias)).parenthesis(
|
|
88
|
+
separated(columns.map((column) => this.formatString(column.name)))
|
|
90
89
|
).add("values").addSeparated(
|
|
91
90
|
query.data.map((row) => this.formatInsertRow(query.into.columns, row))
|
|
92
91
|
).addIf(
|
|
@@ -121,7 +120,7 @@ var Formatter = class {
|
|
|
121
120
|
);
|
|
122
121
|
}
|
|
123
122
|
formatCreateIndex(query, ctx = {}) {
|
|
124
|
-
return raw("create index").addIf(query.ifNotExists, "if not exists").addIdentifier(query.index.name).add("on").addIdentifier(query.table.name).parenthesis(
|
|
123
|
+
return raw("create").addIf(query.index.unique, "unique").add("index").addIf(query.ifNotExists, "if not exists").addIdentifier(query.index.name).add("on").addIdentifier(query.table.name).parenthesis(
|
|
125
124
|
separated(
|
|
126
125
|
query.index.on.map(
|
|
127
126
|
(expr) => this.formatExprValue(expr, {
|
package/dist/lib/Index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Expr, ExprData } from './Expr';
|
|
|
2
2
|
interface PartialIndexData {
|
|
3
3
|
on: Array<ExprData>;
|
|
4
4
|
where?: ExprData;
|
|
5
|
+
unique?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export interface IndexData extends PartialIndexData {
|
|
7
8
|
name: string;
|
|
@@ -10,6 +11,7 @@ export declare class Index {
|
|
|
10
11
|
data: PartialIndexData;
|
|
11
12
|
constructor(data: PartialIndexData);
|
|
12
13
|
where(where: Expr<boolean>): Index;
|
|
14
|
+
unique(): Index;
|
|
13
15
|
}
|
|
14
16
|
export declare function index(...on: Array<Expr<any>>): Index;
|
|
15
17
|
export {};
|
package/dist/lib/Index.js
CHANGED
|
@@ -7,6 +7,9 @@ var Index = class {
|
|
|
7
7
|
where(where) {
|
|
8
8
|
return new Index({ ...this.data, where: ExprData.create(where) });
|
|
9
9
|
}
|
|
10
|
+
unique() {
|
|
11
|
+
return new Index({ ...this.data, unique: true });
|
|
12
|
+
}
|
|
10
13
|
};
|
|
11
14
|
function index(...on) {
|
|
12
15
|
return new Index({ on: on.map(ExprData.create) });
|
package/dist/lib/Table.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>>
|
|
|
13
13
|
insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
|
|
14
14
|
set(data: Update<Table.Normalize<T>>): Cursor.Update<Table.Normalize<T>>;
|
|
15
15
|
createTable(): Cursor.Create;
|
|
16
|
-
as(alias: string):
|
|
16
|
+
as(alias: string): this;
|
|
17
|
+
alias(): Record<string, this>;
|
|
17
18
|
get(name: string): Expr<any>;
|
|
18
19
|
toExpr(): Expr<Table.Normalize<T>>;
|
|
19
20
|
schema(): Schema;
|
|
@@ -48,5 +49,10 @@ export interface TableOptions<T> {
|
|
|
48
49
|
}
|
|
49
50
|
export declare function table<T extends {}>(options: TableOptions<T>): Table<T> & Fields<T>;
|
|
50
51
|
export declare namespace table {
|
|
51
|
-
type infer<T> = Table.Infer<T>;
|
|
52
|
+
export type infer<T> = Table.Infer<T>;
|
|
53
|
+
type Extensions<T> = {
|
|
54
|
+
[key: string]: (this: T, ...args: any[]) => any;
|
|
55
|
+
};
|
|
56
|
+
export function extend<T extends Table<any>, E extends Extensions<T>>(target: T, extensions: E): T & E;
|
|
57
|
+
export {};
|
|
52
58
|
}
|
package/dist/lib/Table.js
CHANGED
|
@@ -58,6 +58,16 @@ var Table = class extends Cursor.SelectMultiple {
|
|
|
58
58
|
as(alias) {
|
|
59
59
|
return new Table({ ...this.schema(), alias });
|
|
60
60
|
}
|
|
61
|
+
alias() {
|
|
62
|
+
return new Proxy(
|
|
63
|
+
{},
|
|
64
|
+
{
|
|
65
|
+
get: (_, key) => {
|
|
66
|
+
return this.as(key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
61
71
|
get(name) {
|
|
62
72
|
return new Expr(ExprData.Field(this.toExpr().expr, name));
|
|
63
73
|
}
|
|
@@ -102,6 +112,18 @@ function table(options) {
|
|
|
102
112
|
indexes
|
|
103
113
|
});
|
|
104
114
|
}
|
|
115
|
+
((table2) => {
|
|
116
|
+
function extend(target, extensions) {
|
|
117
|
+
return new Proxy(target, {
|
|
118
|
+
get(target2, key) {
|
|
119
|
+
if (key === "as")
|
|
120
|
+
return (...args) => extend(target2.as(...args), extensions);
|
|
121
|
+
return key in extensions ? extensions[key].bind(target2) : target2[key];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
table2.extend = extend;
|
|
126
|
+
})(table || (table = {}));
|
|
105
127
|
export {
|
|
106
128
|
Table,
|
|
107
129
|
table
|