rado 0.2.21 → 0.2.23

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.
@@ -1,37 +1,36 @@
1
1
  // src/define/Ops.ts
2
- import { Cursor } from "./Cursor.js";
3
2
  import { ExprData } from "./Expr.js";
4
- import { Query } from "./Query.js";
3
+ import { Query, QueryData } from "./Query.js";
5
4
  import { Schema } from "./Schema.js";
6
5
  import { Table } from "./Table.js";
7
6
  import { Target } from "./Target.js";
8
7
  function select(selection) {
9
- return new Cursor.SelectMultiple(
10
- Query.Select({
8
+ return new Query.SelectMultiple(
9
+ new QueryData.Select({
11
10
  selection: ExprData.create(selection)
12
11
  })
13
12
  );
14
13
  }
15
14
  function from(source) {
16
- const target = source instanceof Cursor ? Target.Query(source[Cursor.Query]) : Target.Table(source[Table.Data]);
17
- return new Cursor.SelectMultiple(
18
- Query.Select({
15
+ const target = Query.isQuery(source) ? new Target.Query(source[Query.Data]) : new Target.Table(source[Table.Data]);
16
+ return new Query.SelectMultiple(
17
+ new QueryData.Select({
19
18
  from: target,
20
- selection: ExprData.Row(target)
19
+ selection: new ExprData.Row(target)
21
20
  })
22
21
  );
23
22
  }
24
23
  function update(table) {
25
- return new Cursor.Update(Query.Update({ table: table[Table.Data] }));
24
+ return new Query.Update(new QueryData.Update({ table: table[Table.Data] }));
26
25
  }
27
26
  function insertInto(table) {
28
- return new Cursor.Insert(table[Table.Data]);
27
+ return new Query.Insert(table[Table.Data]);
29
28
  }
30
29
  function deleteFrom(table) {
31
- return new Cursor.Delete(Query.Delete({ table: table[Table.Data] }));
30
+ return new Query.Delete(new QueryData.Delete({ table: table[Table.Data] }));
32
31
  }
33
32
  function create(...tables) {
34
- return new Cursor.Batch(
33
+ return new Query.Batch(
35
34
  tables.flatMap((table) => Schema.create(table[Table.Data]).queries)
36
35
  );
37
36
  }
@@ -1,15 +1,17 @@
1
1
  export declare enum ParamType {
2
- Value = "Value",
3
- Named = "Named"
2
+ Value = "ParamData.Value",
3
+ Named = "ParamData.Named"
4
4
  }
5
- export type ParamData = {
6
- type: ParamType.Value;
7
- value: any;
8
- } | {
9
- type: ParamType.Named;
10
- name: string;
11
- };
12
- export declare const ParamData: {
13
- Value(value: any): ParamData;
14
- Named(name: string): ParamData;
15
- };
5
+ export declare namespace ParamData {
6
+ class Value {
7
+ value: any;
8
+ type: ParamType.Value;
9
+ constructor(value: any);
10
+ }
11
+ class Named {
12
+ name: string;
13
+ type: ParamType.Named;
14
+ constructor(name: string);
15
+ }
16
+ }
17
+ export type ParamData = ParamData.Value | ParamData.Named;
@@ -1,17 +1,26 @@
1
1
  // src/define/Param.ts
2
2
  var ParamType = /* @__PURE__ */ ((ParamType2) => {
3
- ParamType2["Value"] = "Value";
4
- ParamType2["Named"] = "Named";
3
+ ParamType2["Value"] = "ParamData.Value";
4
+ ParamType2["Named"] = "ParamData.Named";
5
5
  return ParamType2;
6
6
  })(ParamType || {});
7
- var ParamData = {
8
- Value(value) {
9
- return { type: "Value" /* Value */, value };
10
- },
11
- Named(name) {
12
- return { type: "Named" /* Named */, name };
7
+ var ParamData;
8
+ ((ParamData2) => {
9
+ class Value {
10
+ constructor(value) {
11
+ this.value = value;
12
+ }
13
+ type = "ParamData.Value" /* Value */;
13
14
  }
14
- };
15
+ ParamData2.Value = Value;
16
+ class Named {
17
+ constructor(name) {
18
+ this.name = name;
19
+ }
20
+ type = "ParamData.Named" /* Named */;
21
+ }
22
+ ParamData2.Named = Named;
23
+ })(ParamData || (ParamData = {}));
15
24
  export {
16
25
  ParamData,
17
26
  ParamType
@@ -1,29 +1,33 @@
1
+ import { Driver } from '../lib/Driver';
2
+ import { CompileOptions } from '../lib/Formatter';
1
3
  import { ColumnData } from './Column';
2
- import { ExprData } from './Expr';
4
+ import { EV, Expr, ExprData } from './Expr';
3
5
  import { IndexData } from './Index';
4
6
  import { OrderBy } from './OrderBy';
5
- import { TableData } from './Table';
7
+ import { Selection } from './Selection';
8
+ import { Table, TableData } from './Table';
6
9
  import { Target } from './Target';
10
+ declare const DATA: unique symbol;
7
11
  export declare enum QueryType {
8
- Insert = "Insert",
9
- Select = "Select",
10
- Update = "Update",
11
- Delete = "Delete",
12
- CreateTable = "CreateTable",
13
- AlterTable = "AlterTable",
14
- DropTable = "DropTable",
15
- CreateIndex = "CreateIndex",
16
- DropIndex = "DropIndex",
17
- Batch = "Batch",
18
- Transaction = "Transaction",
19
- Raw = "Raw"
12
+ Insert = "QueryData.Insert",
13
+ Select = "QueryData.Select",
14
+ Update = "QueryData.Update",
15
+ Delete = "QueryData.Delete",
16
+ CreateTable = "QueryData.CreateTable",
17
+ AlterTable = "QueryData.AlterTable",
18
+ DropTable = "QueryData.DropTable",
19
+ CreateIndex = "QueryData.CreateIndex",
20
+ DropIndex = "QueryData.DropIndex",
21
+ Batch = "QueryData.Batch",
22
+ Transaction = "QueryData.Transaction",
23
+ Raw = "QueryData.Raw"
20
24
  }
21
- export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.AlterTable | Query.DropTable | Query.CreateIndex | Query.DropIndex | Query.Batch | Query.Transaction | Query.Raw;
22
- export declare namespace Query {
23
- interface QueryBase {
25
+ export type QueryData = QueryData.Insert | QueryData.Select | QueryData.Update | QueryData.Delete | QueryData.CreateTable | QueryData.AlterTable | QueryData.DropTable | QueryData.CreateIndex | QueryData.DropIndex | QueryData.Batch | QueryData.Transaction | QueryData.Raw;
26
+ export declare namespace QueryData {
27
+ abstract class Data<T> {
28
+ abstract type: QueryType;
24
29
  limit?: number;
25
30
  offset?: number;
26
- type: QueryType;
27
31
  where?: ExprData;
28
32
  orderBy?: Array<OrderBy>;
29
33
  groupBy?: Array<ExprData>;
@@ -31,38 +35,34 @@ export declare namespace Query {
31
35
  selection?: ExprData;
32
36
  singleResult?: boolean;
33
37
  validate?: boolean;
38
+ constructor(data: Omit<T, 'type'>);
34
39
  }
35
- interface Insert extends QueryBase {
36
- type: QueryType.Insert;
37
- into: TableData;
38
- data?: Array<any>;
39
- select?: Query.Select;
40
- }
41
- function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
42
- interface Select extends QueryBase {
40
+ export class Select extends Data<Select> {
43
41
  type: QueryType.Select;
44
42
  selection: ExprData;
45
43
  from?: Target;
46
44
  }
47
- function Select(select: Omit<Select, 'type'>): Query.Select;
48
- interface Update extends QueryBase {
45
+ export class Insert extends Data<Insert> {
46
+ type: QueryType.Insert;
47
+ into: TableData;
48
+ data?: Array<any>;
49
+ select?: QueryData.Select;
50
+ }
51
+ export class Update extends Data<Update> {
49
52
  type: QueryType.Update;
50
53
  table: TableData;
51
54
  set?: Record<string, any>;
52
55
  }
53
- function Update(update: Omit<Update, 'type'>): Query.Update;
54
- interface Delete extends QueryBase {
56
+ export class Delete extends Data<Delete> {
55
57
  type: QueryType.Delete;
56
58
  table: TableData;
57
59
  }
58
- function Delete(del: Omit<Delete, 'type'>): Query.Delete;
59
- interface CreateTable extends QueryBase {
60
+ export class CreateTable extends Data<CreateTable> {
60
61
  type: QueryType.CreateTable;
61
62
  table: TableData;
62
63
  ifNotExists?: boolean;
63
64
  }
64
- function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
65
- interface AlterTable extends QueryBase {
65
+ export class AlterTable extends Data<AlterTable> {
66
66
  type: QueryType.AlterTable;
67
67
  table: TableData;
68
68
  alterColumn?: ColumnData;
@@ -76,49 +76,149 @@ export declare namespace Query {
76
76
  from: string;
77
77
  };
78
78
  }
79
- function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
80
- interface DropTable extends QueryBase {
79
+ export class DropTable extends Data<DropTable> {
81
80
  type: QueryType.DropTable;
82
81
  table: TableData;
83
82
  ifExists?: boolean;
84
83
  }
85
- function DropTable(drop: Omit<DropTable, 'type'>): Query.DropTable;
86
- interface CreateIndex extends QueryBase {
84
+ export class CreateIndex extends Data<CreateIndex> {
87
85
  type: QueryType.CreateIndex;
88
86
  table: TableData;
89
87
  index: IndexData;
90
88
  ifNotExists?: boolean;
91
89
  }
92
- function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
93
- interface DropIndex extends QueryBase {
90
+ export class DropIndex extends Data<DropIndex> {
94
91
  type: QueryType.DropIndex;
95
92
  table: TableData;
96
93
  name: string;
97
94
  ifExists?: boolean;
98
95
  }
99
- function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
100
- interface Batch extends QueryBase {
96
+ export class Batch extends Data<Batch> {
101
97
  type: QueryType.Batch;
102
- queries: Array<Query<any>>;
98
+ queries: Array<QueryData>;
103
99
  }
104
- function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
105
- enum TransactionOperation {
100
+ export enum TransactionOperation {
106
101
  Begin = "Begin",
107
102
  Commit = "Commit",
108
103
  Rollback = "Rollback"
109
104
  }
110
- interface Transaction extends QueryBase {
105
+ export class Transaction extends Data<Transaction> {
111
106
  type: QueryType.Transaction;
112
107
  id: string;
113
108
  op: TransactionOperation;
114
109
  }
115
- function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
116
- type RawReturn = 'row' | 'rows' | undefined;
117
- interface Raw extends QueryBase {
110
+ export type RawReturn = 'row' | 'rows' | undefined;
111
+ export class Raw extends Data<Raw> {
118
112
  type: QueryType.Raw;
119
113
  expectedReturn?: 'row' | 'rows';
120
114
  strings: ReadonlyArray<string>;
121
115
  params: Array<any>;
116
+ constructor(data: Omit<Raw, 'type'>);
117
+ }
118
+ export {};
119
+ }
120
+ export declare class Query<T> {
121
+ [Selection.CursorType]: () => T;
122
+ [DATA]: QueryData;
123
+ constructor(query: QueryData);
124
+ static all(strings: TemplateStringsArray, ...params: Array<any>): Query<any>;
125
+ next<T>(cursor: Query<T>): Query<T>;
126
+ on(driver: Driver.Sync): T;
127
+ on(driver: Driver.Async): Promise<T>;
128
+ toSql(driver: Driver, options?: CompileOptions): string;
129
+ toJSON(): QueryData;
130
+ }
131
+ export declare namespace Query {
132
+ class Delete extends Query<{
133
+ rowsAffected: number;
134
+ }> {
135
+ [DATA]: QueryData.Delete;
136
+ where(...where: Array<EV<boolean>>): Delete;
137
+ take(limit: number | undefined): Delete;
138
+ skip(offset: number | undefined): Delete;
139
+ }
140
+ class Update<Definition> extends Query<{
141
+ rowsAffected: number;
142
+ }> {
143
+ [DATA]: QueryData.Update;
144
+ set(set: Table.Update<Definition>): Update<Definition>;
145
+ where(...where: Array<EV<boolean>>): Update<Definition>;
146
+ take(limit: number | undefined): Update<Definition>;
147
+ skip(offset: number | undefined): Update<Definition>;
148
+ }
149
+ class InsertValuesReturning<T> extends Query<T> {
150
+ }
151
+ class Inserted extends Query<{
152
+ rowsAffected: number;
153
+ }> {
154
+ [DATA]: QueryData.Insert;
155
+ constructor(query: QueryData.Insert);
156
+ returning<X extends Selection>(selection: X): InsertValuesReturning<Selection.Infer<X>>;
157
+ }
158
+ class Insert<Definition> {
159
+ protected into: TableData;
160
+ constructor(into: TableData);
161
+ selection(query: Query.SelectMultiple<Table.Select<Definition>>): Inserted;
162
+ values(...data: Array<Table.Insert<Definition>>): Inserted;
163
+ }
164
+ class CreateTable extends Query<void> {
165
+ protected table: TableData;
166
+ constructor(table: TableData);
122
167
  }
123
- function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
168
+ class Batch<T = void> extends Query<T> {
169
+ protected queries: Array<QueryData>;
170
+ [DATA]: QueryData.Batch;
171
+ constructor(queries: Array<QueryData>);
172
+ next<T>(cursor: Query<T>): Query<T>;
173
+ }
174
+ class SelectMultiple<Row> extends Query<Array<Row>> {
175
+ [DATA]: QueryData.Select;
176
+ constructor(query: QueryData.Select);
177
+ leftJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectMultiple<Row>;
178
+ innerJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectMultiple<Row>;
179
+ select<X extends Selection>(selection: X): SelectMultiple<Selection.Infer<X>>;
180
+ count(): SelectSingle<number>;
181
+ orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<Row>;
182
+ groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<Row>;
183
+ maybeFirst(): SelectSingle<Row | undefined>;
184
+ first(): SelectSingle<Row>;
185
+ where(...where: Array<EV<boolean>>): SelectMultiple<Row>;
186
+ take(limit: number | undefined): SelectMultiple<Row>;
187
+ skip(offset: number | undefined): SelectMultiple<Row>;
188
+ [Expr.ToExpr](): Expr<Row>;
189
+ }
190
+ class TableSelect<Definition> extends SelectMultiple<Table.Select<Definition>> {
191
+ protected table: TableData;
192
+ [DATA]: QueryData.Select;
193
+ constructor(table: TableData, conditions?: Array<EV<boolean>>);
194
+ as(alias: string): Table<Definition>;
195
+ create(): CreateTable;
196
+ insertSelect(query: SelectMultiple<Table.Insert<Definition>>): Inserted;
197
+ insertOne(record: Table.Insert<Definition>): Query<Table.Select<Definition>>;
198
+ insertAll(data: Array<Table.Insert<Definition>>): Inserted;
199
+ set(data: Table.Update<Definition>): Update<Definition>;
200
+ delete(): Delete;
201
+ get(name: string): Expr<any>;
202
+ }
203
+ class SelectSingle<Row> extends Query<Row> {
204
+ [DATA]: QueryData.Select;
205
+ constructor(query: QueryData.Select);
206
+ leftJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectSingle<Row>;
207
+ innerJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectSingle<Row>;
208
+ select<X extends Selection>(selection: X): SelectSingle<Selection.Infer<X>>;
209
+ orderBy(...orderBy: Array<OrderBy>): SelectSingle<Row>;
210
+ groupBy(...groupBy: Array<Expr<any>>): SelectSingle<Row>;
211
+ where(...where: Array<EV<boolean>>): SelectSingle<Row>;
212
+ take(limit: number | undefined): SelectSingle<Row>;
213
+ skip(offset: number | undefined): SelectSingle<Row>;
214
+ all(): SelectMultiple<Row>;
215
+ [Expr.ToExpr](): Expr<Row>;
216
+ }
217
+ }
218
+ export declare namespace Query {
219
+ const Data: typeof DATA;
220
+ function isQuery<T>(input: any): input is Query<T>;
221
+ function isSingle<T>(input: any): input is Query.SelectSingle<T>;
222
+ function isMultiple<T>(input: any): input is Query.SelectMultiple<T>;
124
223
  }
224
+ export {};