rado 0.1.23 → 0.1.25

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.
Files changed (80) hide show
  1. package/README.md +1 -1
  2. package/dist/driver/better-sqlite3.d.ts +15 -17
  3. package/dist/driver/better-sqlite3.js +25 -18
  4. package/dist/driver/sql.js.d.ts +15 -17
  5. package/dist/driver/sql.js.js +29 -26
  6. package/dist/driver/sqlite3.d.ts +18 -20
  7. package/dist/driver/sqlite3.js +40 -29
  8. package/dist/index.d.ts +20 -20
  9. package/dist/lib/Column.d.ts +57 -57
  10. package/dist/lib/Cursor.d.ts +78 -77
  11. package/dist/lib/Cursor.js +3 -0
  12. package/dist/lib/Driver.d.ts +105 -89
  13. package/dist/lib/Driver.js +72 -28
  14. package/dist/lib/Expr.d.ts +154 -154
  15. package/dist/lib/Fields.d.ts +13 -13
  16. package/dist/lib/Formatter.d.ts +56 -56
  17. package/dist/lib/Formatter.js +14 -4
  18. package/dist/lib/Functions.d.ts +7 -7
  19. package/dist/lib/Id.d.ts +3 -3
  20. package/dist/lib/Index.d.ts +17 -17
  21. package/dist/lib/Index.js +3 -3
  22. package/dist/lib/Ops.d.ts +8 -8
  23. package/dist/lib/OrderBy.d.ts +9 -9
  24. package/dist/lib/Param.d.ts +20 -15
  25. package/dist/lib/Param.js +10 -1
  26. package/dist/lib/Query.d.ts +108 -108
  27. package/dist/lib/Sanitizer.d.ts +4 -4
  28. package/dist/lib/Schema.d.ts +18 -18
  29. package/dist/lib/Schema.js +4 -4
  30. package/dist/lib/Selection.d.ts +20 -20
  31. package/dist/lib/Statement.d.ts +71 -61
  32. package/dist/lib/Statement.js +46 -5
  33. package/dist/lib/Table.d.ts +59 -58
  34. package/dist/lib/Table.js +4 -7
  35. package/dist/lib/Target.d.ts +30 -30
  36. package/dist/lib/Update.d.ts +4 -4
  37. package/dist/sqlite/SqliteFormatter.d.ts +11 -11
  38. package/dist/sqlite/SqliteFunctions.d.ts +156 -156
  39. package/dist/sqlite/SqliteSchema.d.ts +25 -24
  40. package/dist/sqlite/SqliteSchema.js +5 -4
  41. package/dist/sqlite.d.ts +2 -2
  42. package/package.json +47 -47
  43. package/dist/Column.d.ts +0 -41
  44. package/dist/Column.js +0 -58
  45. package/dist/Cursor.d.ts +0 -77
  46. package/dist/Cursor.js +0 -211
  47. package/dist/Driver.d.ts +0 -72
  48. package/dist/Driver.js +0 -145
  49. package/dist/Expr.d.ts +0 -149
  50. package/dist/Expr.js +0 -284
  51. package/dist/Fields.d.ts +0 -9
  52. package/dist/Fields.js +0 -0
  53. package/dist/Formatter.d.ts +0 -50
  54. package/dist/Formatter.js +0 -453
  55. package/dist/Functions.d.ts +0 -8
  56. package/dist/Functions.js +0 -11
  57. package/dist/Key.d.ts +0 -5
  58. package/dist/Ops.d.ts +0 -8
  59. package/dist/Ops.js +0 -46
  60. package/dist/OrderBy.d.ts +0 -9
  61. package/dist/OrderBy.js +0 -9
  62. package/dist/Param.d.ts +0 -15
  63. package/dist/Param.js +0 -18
  64. package/dist/Query.d.ts +0 -94
  65. package/dist/Query.js +0 -57
  66. package/dist/Sanitizer.d.ts +0 -4
  67. package/dist/Sanitizer.js +0 -0
  68. package/dist/Schema.d.ts +0 -10
  69. package/dist/Selection.d.ts +0 -18
  70. package/dist/Selection.js +0 -0
  71. package/dist/Statement.d.ts +0 -57
  72. package/dist/Statement.js +0 -184
  73. package/dist/Table.d.ts +0 -47
  74. package/dist/Table.js +0 -82
  75. package/dist/Target.d.ts +0 -30
  76. package/dist/Target.js +0 -37
  77. package/dist/Update.d.ts +0 -4
  78. package/dist/Update.js +0 -0
  79. package/dist/sqlite/index.d.ts +0 -2
  80. package/dist/sqlite/index.js +0 -3
package/dist/Query.js DELETED
@@ -1,57 +0,0 @@
1
- // src/Query.ts
2
- var QueryType = /* @__PURE__ */ ((QueryType2) => {
3
- QueryType2["Insert"] = "Insert";
4
- QueryType2["Select"] = "Select";
5
- QueryType2["Update"] = "Update";
6
- QueryType2["Delete"] = "Delete";
7
- QueryType2["CreateTable"] = "CreateTable";
8
- QueryType2["Batch"] = "Batch";
9
- QueryType2["Transaction"] = "Transaction";
10
- QueryType2["Raw"] = "Raw";
11
- return QueryType2;
12
- })(QueryType || {});
13
- var Query;
14
- ((Query2) => {
15
- function Insert(insert) {
16
- return { type: "Insert" /* Insert */, ...insert };
17
- }
18
- Query2.Insert = Insert;
19
- function Select(select) {
20
- return { type: "Select" /* Select */, ...select };
21
- }
22
- Query2.Select = Select;
23
- function Update(update) {
24
- return { type: "Update" /* Update */, ...update };
25
- }
26
- Query2.Update = Update;
27
- function Delete(del) {
28
- return { type: "Delete" /* Delete */, ...del };
29
- }
30
- Query2.Delete = Delete;
31
- function CreateTable(create) {
32
- return { type: "CreateTable" /* CreateTable */, ...create };
33
- }
34
- Query2.CreateTable = CreateTable;
35
- function Batch(batch) {
36
- return { type: "Batch" /* Batch */, ...batch };
37
- }
38
- Query2.Batch = Batch;
39
- let TransactionOperation;
40
- ((TransactionOperation2) => {
41
- TransactionOperation2["Begin"] = "Begin";
42
- TransactionOperation2["Commit"] = "Commit";
43
- TransactionOperation2["Rollback"] = "Rollback";
44
- })(TransactionOperation = Query2.TransactionOperation || (Query2.TransactionOperation = {}));
45
- function Transaction(transaction) {
46
- return { type: "Transaction" /* Transaction */, ...transaction };
47
- }
48
- Query2.Transaction = Transaction;
49
- function Raw(raw) {
50
- return { type: "Raw" /* Raw */, ...raw };
51
- }
52
- Query2.Raw = Raw;
53
- })(Query || (Query = {}));
54
- export {
55
- Query,
56
- QueryType
57
- };
@@ -1,4 +0,0 @@
1
- export interface Sanitizer {
2
- escapeValue(value: any): string;
3
- escapeIdentifier(ident: string): string;
4
- }
package/dist/Sanitizer.js DELETED
File without changes
package/dist/Schema.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { ColumnData } from './Column';
2
- import { Query } from './Query';
3
- export interface Schema {
4
- name: string;
5
- alias?: string;
6
- columns: Record<string, ColumnData>;
7
- }
8
- export declare namespace Schema {
9
- function diff(a: Schema, b: Schema): Array<Query.AlterTable>;
10
- }
@@ -1,18 +0,0 @@
1
- import type { Cursor } from './Cursor';
2
- import type { Expr } from './Expr';
3
- type SelectionBase = Expr<any> | Cursor.SelectMultiple<any> | Cursor.SelectSingle<any>;
4
- interface SelectionRecord extends Record<string, Selection> {
5
- }
6
- export type Selection = SelectionBase | SelectionRecord;
7
- export declare namespace Selection {
8
- type Infer<T> = T extends {
9
- __tableType: infer K;
10
- } ? K : T extends {
11
- __cursortype: infer K;
12
- } ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
13
- [K in keyof T]: Infer<T[K]>;
14
- } : T;
15
- type With<A, B> = Expr<Combine<A, B>>;
16
- type Combine<A, B> = Omit<A, keyof Infer<B>> & Infer<B>;
17
- }
18
- export {};
package/dist/Selection.js DELETED
File without changes
@@ -1,57 +0,0 @@
1
- import { Sanitizer } from './Sanitizer';
2
- declare const enum TokenType {
3
- Raw = "Raw",
4
- Identifier = "Identifier",
5
- Value = "Value",
6
- Indent = "Indent",
7
- Dedent = "Dedent"
8
- }
9
- declare class Token {
10
- type: TokenType;
11
- data: any;
12
- constructor(type: TokenType, data: any);
13
- static Raw(data: string): Token;
14
- static Indent(): Token;
15
- static Dedent(): Token;
16
- static Identifier(data: string): Token;
17
- static Value(data: any): Token;
18
- }
19
- export declare class Statement {
20
- tokens: Array<Token>;
21
- constructor(tokens: Array<Token>);
22
- concat(...tokens: Array<Token | Statement>): Statement;
23
- static create(from: string | Statement): Statement;
24
- static tag(strings: ReadonlyArray<string>, ...params: Array<any>): Statement;
25
- space(): Statement;
26
- call(method: string, ...args: Array<Statement>): Statement;
27
- addCall(method: string, ...args: Array<Statement>): Statement;
28
- add(addition: undefined | string | Statement): Statement;
29
- addLine(addition: undefined | string | Statement): Statement;
30
- addIf(condition: any, addition: string | Statement | (() => string | Statement)): Statement;
31
- indent(): Statement;
32
- dedent(): Statement;
33
- newline(): Statement;
34
- identifier(name: string): Statement;
35
- addIdentifier(name: string): Statement;
36
- value(value: any): Statement;
37
- addValue(value: any): Statement;
38
- raw(query: string): Statement;
39
- parenthesis(inner: string | Statement): Statement;
40
- addParenthesis(stmnt: string | Statement): Statement;
41
- separated(input: Array<Statement>, separator?: string): Statement;
42
- addSeparated(input: Array<Statement>, separator?: string): Statement;
43
- isEmpty(): boolean;
44
- compile(sanitizer: Sanitizer, formatInline?: boolean): Statement.Compiled;
45
- }
46
- export declare namespace Statement {
47
- type Compiled = [sql: string, params: Array<any>];
48
- }
49
- export declare function newline(): Statement;
50
- export declare function raw(raw: string): Statement;
51
- export declare function identifier(name: string): Statement;
52
- export declare function value(value: any): Statement;
53
- export declare function empty(): Statement;
54
- export declare function parenthesis(stmnt: Statement): Statement;
55
- export declare function call(method: string, ...args: Array<Statement>): Statement;
56
- export declare function separated(input: Array<Statement>, separator?: string): Statement;
57
- export {};
package/dist/Statement.js DELETED
@@ -1,184 +0,0 @@
1
- // src/Statement.ts
2
- var Token = class {
3
- constructor(type, data) {
4
- this.type = type;
5
- this.data = data;
6
- }
7
- static Raw(data) {
8
- return new Token("Raw" /* Raw */, data);
9
- }
10
- static Indent() {
11
- return new Token("Indent" /* Indent */, null);
12
- }
13
- static Dedent() {
14
- return new Token("Dedent" /* Dedent */, null);
15
- }
16
- static Identifier(data) {
17
- return new Token("Identifier" /* Identifier */, data);
18
- }
19
- static Value(data) {
20
- return new Token("Value" /* Value */, data);
21
- }
22
- };
23
- var SEPARATE = ",";
24
- var WHITESPACE = " ";
25
- var NEWLINE = "\n";
26
- var Statement = class {
27
- constructor(tokens) {
28
- this.tokens = tokens;
29
- }
30
- concat(...tokens) {
31
- return new Statement(
32
- this.tokens.concat(
33
- ...tokens.flatMap((t) => t instanceof Statement ? t.tokens : [t])
34
- )
35
- );
36
- }
37
- static create(from) {
38
- return typeof from === "string" ? raw(from) : from;
39
- }
40
- static ofTemplate(strings, params) {
41
- return new Statement(
42
- strings.flatMap((s, i) => [Token.Raw(s), Token.Value(params[i])]).slice(0, -1)
43
- );
44
- }
45
- space() {
46
- return this.concat(Token.Raw(WHITESPACE));
47
- }
48
- call(method, ...args) {
49
- return this.identifier(method).parenthesis(separated(args));
50
- }
51
- addCall(method, ...args) {
52
- return this.space().call(method, ...args);
53
- }
54
- add(addition) {
55
- if (!addition)
56
- return this;
57
- if (addition instanceof Statement && addition.isEmpty())
58
- return this;
59
- return this.space().concat(Statement.create(addition));
60
- }
61
- addLine(addition) {
62
- if (!addition)
63
- return this;
64
- if (addition instanceof Statement && addition.isEmpty())
65
- return this;
66
- return this.newline().concat(Statement.create(addition));
67
- }
68
- addIf(condition, addition) {
69
- if (!condition)
70
- return this;
71
- return this.add(typeof addition === "function" ? addition() : addition);
72
- }
73
- indent() {
74
- return this.concat(Token.Indent());
75
- }
76
- dedent() {
77
- return this.concat(Token.Dedent());
78
- }
79
- newline() {
80
- return this.raw(NEWLINE);
81
- }
82
- identifier(name) {
83
- return this.concat(Token.Identifier(name));
84
- }
85
- addIdentifier(name) {
86
- return this.space().identifier(name);
87
- }
88
- value(value2) {
89
- return this.concat(Token.Value(value2));
90
- }
91
- addValue(value2) {
92
- return this.space().value(value2);
93
- }
94
- raw(query) {
95
- if (!query)
96
- return this;
97
- return this.concat(Token.Raw(query));
98
- }
99
- parenthesis(inner) {
100
- return this.raw("(").indent().newline().concat(Statement.create(inner)).dedent().newline().raw(")");
101
- }
102
- addParenthesis(stmnt) {
103
- return this.space().parenthesis(stmnt);
104
- }
105
- separated(input, separator = SEPARATE) {
106
- return this.concat(
107
- ...input.flatMap(
108
- (stmt, i) => i === 0 ? stmt.tokens : [Token.Raw(separator), Token.Raw(NEWLINE), ...stmt.tokens]
109
- )
110
- );
111
- }
112
- addSeparated(input, separator = SEPARATE) {
113
- return this.space().separated(input, separator);
114
- }
115
- isEmpty() {
116
- return this.tokens.length === 0 || this.tokens.length === 1 && this.tokens[0].type === "Raw" /* Raw */ && this.tokens[0].data === "";
117
- }
118
- compile(sanitizer, formatInline = false) {
119
- let sql = "", params = [], indent = "";
120
- for (const token of this.tokens) {
121
- switch (token.type) {
122
- case "Raw" /* Raw */:
123
- if (token.data === NEWLINE)
124
- sql += NEWLINE + indent;
125
- else
126
- sql += token.data;
127
- break;
128
- case "Identifier" /* Identifier */:
129
- sql += sanitizer.escapeIdent(token.data);
130
- break;
131
- case "Value" /* Value */:
132
- if (formatInline) {
133
- sql += sanitizer.escapeValue(token.data);
134
- } else {
135
- sql += "?";
136
- params.push(token.data === void 0 ? null : token.data);
137
- }
138
- break;
139
- case "Indent" /* Indent */:
140
- indent += " ";
141
- break;
142
- case "Dedent" /* Dedent */:
143
- indent = indent.slice(0, -2);
144
- break;
145
- }
146
- }
147
- return [sql, params];
148
- }
149
- };
150
- function newline() {
151
- return new Statement([Token.Raw(NEWLINE)]);
152
- }
153
- function raw(raw2) {
154
- return new Statement([Token.Raw(raw2)]);
155
- }
156
- function identifier(name) {
157
- return new Statement([Token.Identifier(name)]);
158
- }
159
- function value(value2) {
160
- return new Statement([Token.Value(value2)]);
161
- }
162
- function empty() {
163
- return new Statement([]);
164
- }
165
- function parenthesis(stmnt) {
166
- return empty().parenthesis(stmnt);
167
- }
168
- function call(method, ...args) {
169
- return identifier(method).parenthesis(separated(args));
170
- }
171
- function separated(input, separator = SEPARATE) {
172
- return empty().separated(input, separator);
173
- }
174
- export {
175
- Statement,
176
- call,
177
- empty,
178
- identifier,
179
- newline,
180
- parenthesis,
181
- raw,
182
- separated,
183
- value
184
- };
package/dist/Table.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import { Column } from './Column';
2
- import { Cursor } from './Cursor';
3
- import { Expr } from './Expr';
4
- import { Fields } from './Fields';
5
- import { Schema } from './Schema';
6
- import { Update } from './Update';
7
- export declare class Table<T> extends Cursor.SelectMultiple<T> {
8
- /** @internal */
9
- protected __tableType: T;
10
- constructor(schema: Schema);
11
- insertOne(record: Table.Insert<T>): Cursor.Batch<T>;
12
- insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
13
- set(data: Update<T>): Cursor.Update<T>;
14
- createTable(): Cursor.Create;
15
- as(alias: string): Table<T> & Fields<T>;
16
- get(name: string): Expr<any>;
17
- toExpr(): Expr<T>;
18
- schema(): Schema;
19
- }
20
- export declare namespace Table {
21
- type Intersection<A, B> = A & B extends infer U ? {
22
- [P in keyof U]: U[P];
23
- } : never;
24
- type OptionalKeys<T> = {
25
- [K in keyof T]: null extends T[K] ? K : T[K] extends Column.Optional ? K : never;
26
- }[keyof T];
27
- type RequiredKeys<T> = {
28
- [K in keyof T]: null extends T[K] ? never : T[K] extends Column.Optional ? never : K;
29
- }[keyof T];
30
- type Optionals<T> = {
31
- [K in keyof T]?: T[K] extends Column.Optional & infer V ? V : T[K];
32
- };
33
- export type Insert<T> = Intersection<Optionals<Pick<T, OptionalKeys<T>>>, Pick<T, RequiredKeys<T>>>;
34
- export {};
35
- }
36
- export interface TableOptions<T> {
37
- name: string;
38
- alias?: string;
39
- columns: {
40
- [K in keyof T]: Column<T[K]>;
41
- };
42
- indexes?: Record<string, Array<Expr<any>>>;
43
- }
44
- export declare function table<T extends {}>(options: TableOptions<T>): Table<T> & Fields<T>;
45
- export declare namespace table {
46
- type infer<T> = T extends Table<infer U> ? U : never;
47
- }
package/dist/Table.js DELETED
@@ -1,82 +0,0 @@
1
- // src/Table.ts
2
- import { Cursor } from "./Cursor";
3
- import { Expr, ExprData } from "./Expr";
4
- import { Query } from "./Query";
5
- import { Target } from "./Target";
6
- var Table = class extends Cursor.SelectMultiple {
7
- constructor(data) {
8
- super(
9
- Query.Select({
10
- from: Target.Table(data),
11
- selection: ExprData.Row(Target.Table(data))
12
- })
13
- );
14
- Object.defineProperty(this, "data", {
15
- enumerable: false,
16
- value: () => data
17
- });
18
- if (data.columns)
19
- for (const column of Object.keys(data.columns)) {
20
- Object.defineProperty(this, column, {
21
- enumerable: true,
22
- get: () => this.get(column)
23
- });
24
- }
25
- return new Proxy(this, {
26
- get(target, key) {
27
- return key in target ? target[key] : target.get(key);
28
- }
29
- });
30
- }
31
- insertOne(record) {
32
- return new Cursor.Batch([
33
- Query.Insert({
34
- into: this.data(),
35
- data: [record],
36
- selection: ExprData.Row(Target.Table(this.data())),
37
- singleResult: true
38
- })
39
- ]);
40
- }
41
- insertAll(data) {
42
- return new Cursor.Insert(this.data()).values(...data);
43
- }
44
- set(data) {
45
- return new Cursor.Update(
46
- Query.Update({
47
- table: this.data()
48
- })
49
- ).set(data);
50
- }
51
- createTable() {
52
- return new Cursor.Create(this.data());
53
- }
54
- as(alias) {
55
- return new Table({ ...this.data(), alias });
56
- }
57
- get(name) {
58
- return new Expr(ExprData.Field(this.toExpr().expr, name));
59
- }
60
- toExpr() {
61
- return new Expr(ExprData.Row(Target.Table(this.data())));
62
- }
63
- /** @internal */
64
- data() {
65
- throw new Error("Not implemented");
66
- }
67
- };
68
- function table(options) {
69
- return new Table({
70
- ...options,
71
- columns: Object.fromEntries(
72
- Object.entries(options.columns).map(([key, column]) => {
73
- const { data } = column;
74
- return [key, { ...data, name: data.name || key }];
75
- })
76
- )
77
- });
78
- }
79
- export {
80
- Table,
81
- table
82
- };
package/dist/Target.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { ExprData } from './Expr';
2
- import { Schema } from './Schema';
3
- export declare const enum TargetType {
4
- Each = "Each",
5
- Table = "Table",
6
- Join = "Join"
7
- }
8
- export type Target = Target.Each | Target.Table | Target.Join;
9
- export declare namespace Target {
10
- interface Each {
11
- type: TargetType.Each;
12
- expr: ExprData;
13
- alias: string;
14
- }
15
- function Each(expr: ExprData, alias: string): Each;
16
- interface Table {
17
- type: TargetType.Table;
18
- table: Schema;
19
- }
20
- function Table(table: Schema): Table;
21
- interface Join {
22
- type: TargetType.Join;
23
- left: Target;
24
- right: Target;
25
- joinType: 'left' | 'inner';
26
- on: ExprData;
27
- }
28
- function Join(left: Target, right: Target, joinType: 'left' | 'inner', on: ExprData): Join;
29
- function source(from: Target): Schema | undefined;
30
- }
package/dist/Target.js DELETED
@@ -1,37 +0,0 @@
1
- // src/Target.ts
2
- var TargetType = /* @__PURE__ */ ((TargetType2) => {
3
- TargetType2["Each"] = "Each";
4
- TargetType2["Table"] = "Table";
5
- TargetType2["Join"] = "Join";
6
- return TargetType2;
7
- })(TargetType || {});
8
- var Target;
9
- ((Target2) => {
10
- function Each(expr, alias) {
11
- return { type: "Each" /* Each */, expr, alias };
12
- }
13
- Target2.Each = Each;
14
- function Table(table) {
15
- return { type: "Table" /* Table */, table };
16
- }
17
- Target2.Table = Table;
18
- function Join(left, right, joinType, on) {
19
- return { type: "Join" /* Join */, left, right, joinType, on };
20
- }
21
- Target2.Join = Join;
22
- function source(from) {
23
- switch (from.type) {
24
- case "Table" /* Table */:
25
- return from.table;
26
- case "Join" /* Join */:
27
- return source(from.left);
28
- default:
29
- return void 0;
30
- }
31
- }
32
- Target2.source = source;
33
- })(Target || (Target = {}));
34
- export {
35
- Target,
36
- TargetType
37
- };
package/dist/Update.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { EV } from './Expr';
2
- export type Update<Row> = Partial<{
3
- [K in keyof Row]: EV<Row[K]>;
4
- }>;
package/dist/Update.js DELETED
File without changes
@@ -1,2 +0,0 @@
1
- export * from './SqliteFormatter';
2
- export * from './SqliteFunctions';
@@ -1,3 +0,0 @@
1
- // src/sqlite/index.ts
2
- export * from "./SqliteFormatter";
3
- export * from "./SqliteFunctions";