rado 0.1.14 → 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.
@@ -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").addCall(
88
- query.into.name,
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(
@@ -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): Table<T> & Fields<T>;
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {