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.
- package/README.md +1 -1
- package/dist/driver/better-sqlite3.d.ts +15 -17
- package/dist/driver/better-sqlite3.js +25 -18
- package/dist/driver/sql.js.d.ts +15 -17
- package/dist/driver/sql.js.js +29 -26
- package/dist/driver/sqlite3.d.ts +18 -20
- package/dist/driver/sqlite3.js +40 -29
- package/dist/index.d.ts +20 -20
- package/dist/lib/Column.d.ts +57 -57
- package/dist/lib/Cursor.d.ts +78 -77
- package/dist/lib/Cursor.js +3 -0
- package/dist/lib/Driver.d.ts +105 -89
- package/dist/lib/Driver.js +72 -28
- package/dist/lib/Expr.d.ts +154 -154
- package/dist/lib/Fields.d.ts +13 -13
- package/dist/lib/Formatter.d.ts +56 -56
- package/dist/lib/Formatter.js +14 -4
- package/dist/lib/Functions.d.ts +7 -7
- package/dist/lib/Id.d.ts +3 -3
- package/dist/lib/Index.d.ts +17 -17
- package/dist/lib/Index.js +3 -3
- package/dist/lib/Ops.d.ts +8 -8
- package/dist/lib/OrderBy.d.ts +9 -9
- package/dist/lib/Param.d.ts +20 -15
- package/dist/lib/Param.js +10 -1
- package/dist/lib/Query.d.ts +108 -108
- package/dist/lib/Sanitizer.d.ts +4 -4
- package/dist/lib/Schema.d.ts +18 -18
- package/dist/lib/Schema.js +4 -4
- package/dist/lib/Selection.d.ts +20 -20
- package/dist/lib/Statement.d.ts +71 -61
- package/dist/lib/Statement.js +46 -5
- package/dist/lib/Table.d.ts +59 -58
- package/dist/lib/Table.js +4 -7
- package/dist/lib/Target.d.ts +30 -30
- package/dist/lib/Update.d.ts +4 -4
- package/dist/sqlite/SqliteFormatter.d.ts +11 -11
- package/dist/sqlite/SqliteFunctions.d.ts +156 -156
- package/dist/sqlite/SqliteSchema.d.ts +25 -24
- package/dist/sqlite/SqliteSchema.js +5 -4
- package/dist/sqlite.d.ts +2 -2
- package/package.json +47 -47
- package/dist/Column.d.ts +0 -41
- package/dist/Column.js +0 -58
- package/dist/Cursor.d.ts +0 -77
- package/dist/Cursor.js +0 -211
- package/dist/Driver.d.ts +0 -72
- package/dist/Driver.js +0 -145
- package/dist/Expr.d.ts +0 -149
- package/dist/Expr.js +0 -284
- package/dist/Fields.d.ts +0 -9
- package/dist/Fields.js +0 -0
- package/dist/Formatter.d.ts +0 -50
- package/dist/Formatter.js +0 -453
- package/dist/Functions.d.ts +0 -8
- package/dist/Functions.js +0 -11
- package/dist/Key.d.ts +0 -5
- package/dist/Ops.d.ts +0 -8
- package/dist/Ops.js +0 -46
- package/dist/OrderBy.d.ts +0 -9
- package/dist/OrderBy.js +0 -9
- package/dist/Param.d.ts +0 -15
- package/dist/Param.js +0 -18
- package/dist/Query.d.ts +0 -94
- package/dist/Query.js +0 -57
- package/dist/Sanitizer.d.ts +0 -4
- package/dist/Sanitizer.js +0 -0
- package/dist/Schema.d.ts +0 -10
- package/dist/Selection.d.ts +0 -18
- package/dist/Selection.js +0 -0
- package/dist/Statement.d.ts +0 -57
- package/dist/Statement.js +0 -184
- package/dist/Table.d.ts +0 -47
- package/dist/Table.js +0 -82
- package/dist/Target.d.ts +0 -30
- package/dist/Target.js +0 -37
- package/dist/Update.d.ts +0 -4
- package/dist/Update.js +0 -0
- package/dist/sqlite/index.d.ts +0 -2
- package/dist/sqlite/index.js +0 -3
package/dist/lib/Param.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { Expr } from './Expr';
|
|
2
|
+
export declare enum ParamType {
|
|
3
|
+
Value = "Value",
|
|
4
|
+
Named = "Named"
|
|
5
|
+
}
|
|
6
|
+
export type ParamData = {
|
|
7
|
+
type: ParamType.Value;
|
|
8
|
+
value: any;
|
|
9
|
+
} | {
|
|
10
|
+
type: ParamType.Named;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const ParamData: {
|
|
14
|
+
Value(value: any): ParamData;
|
|
15
|
+
Named(name: string): ParamData;
|
|
16
|
+
};
|
|
17
|
+
export type Params<T> = {
|
|
18
|
+
[K in keyof T]: Expr<T[K]>;
|
|
19
|
+
};
|
|
20
|
+
export declare function createParams<T>(): Params<T>;
|
package/dist/lib/Param.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/lib/Param.ts
|
|
2
|
+
import { Expr, ExprData } from "./Expr.js";
|
|
2
3
|
var ParamType = /* @__PURE__ */ ((ParamType2) => {
|
|
3
4
|
ParamType2["Value"] = "Value";
|
|
4
5
|
ParamType2["Named"] = "Named";
|
|
@@ -12,7 +13,15 @@ var ParamData = {
|
|
|
12
13
|
return { type: "Named" /* Named */, name };
|
|
13
14
|
}
|
|
14
15
|
};
|
|
16
|
+
function createParams() {
|
|
17
|
+
return new Proxy({}, {
|
|
18
|
+
get(target, prop) {
|
|
19
|
+
return new Expr(ExprData.Param(ParamData.Named(prop)));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
15
23
|
export {
|
|
16
24
|
ParamData,
|
|
17
|
-
ParamType
|
|
25
|
+
ParamType,
|
|
26
|
+
createParams
|
|
18
27
|
};
|
package/dist/lib/Query.d.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { ColumnData } from './Column';
|
|
2
|
-
import { ExprData } from './Expr';
|
|
3
|
-
import { IndexData } from './Index';
|
|
4
|
-
import { OrderBy } from './OrderBy';
|
|
5
|
-
import { Schema } from './Schema';
|
|
6
|
-
import { Target } from './Target';
|
|
7
|
-
export declare enum QueryType {
|
|
8
|
-
Insert = "Insert",
|
|
9
|
-
Select = "Select",
|
|
10
|
-
Update = "Update",
|
|
11
|
-
Delete = "Delete",
|
|
12
|
-
CreateTable = "CreateTable",
|
|
13
|
-
CreateIndex = "CreateIndex",
|
|
14
|
-
DropIndex = "DropIndex",
|
|
15
|
-
AlterTable = "AlterTable",
|
|
16
|
-
Batch = "Batch",
|
|
17
|
-
Transaction = "Transaction",
|
|
18
|
-
Raw = "Raw"
|
|
19
|
-
}
|
|
20
|
-
export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.CreateIndex | Query.DropIndex | Query.AlterTable | Query.Batch | Query.Transaction | Query.Raw;
|
|
21
|
-
export declare namespace Query {
|
|
22
|
-
interface QueryBase {
|
|
23
|
-
limit?: number;
|
|
24
|
-
offset?: number;
|
|
25
|
-
type: QueryType;
|
|
26
|
-
where?: ExprData;
|
|
27
|
-
orderBy?: Array<OrderBy>;
|
|
28
|
-
groupBy?: Array<ExprData>;
|
|
29
|
-
having?: ExprData;
|
|
30
|
-
selection?: ExprData;
|
|
31
|
-
singleResult?: boolean;
|
|
32
|
-
}
|
|
33
|
-
interface Insert extends QueryBase {
|
|
34
|
-
type: QueryType.Insert;
|
|
35
|
-
into: Schema;
|
|
36
|
-
data: Array<any>;
|
|
37
|
-
}
|
|
38
|
-
function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
|
|
39
|
-
interface Select extends QueryBase {
|
|
40
|
-
type: QueryType.Select;
|
|
41
|
-
selection: ExprData;
|
|
42
|
-
from: Target;
|
|
43
|
-
}
|
|
44
|
-
function Select(select: Omit<Select, 'type'>): Query.Select;
|
|
45
|
-
interface Update extends QueryBase {
|
|
46
|
-
type: QueryType.Update;
|
|
47
|
-
table: Schema;
|
|
48
|
-
set?: Record<string, any>;
|
|
49
|
-
}
|
|
50
|
-
function Update(update: Omit<Update, 'type'>): Query.Update;
|
|
51
|
-
interface Delete extends QueryBase {
|
|
52
|
-
type: QueryType.Delete;
|
|
53
|
-
table: Schema;
|
|
54
|
-
}
|
|
55
|
-
function Delete(del: Omit<Delete, 'type'>): Query.Delete;
|
|
56
|
-
interface CreateTable extends QueryBase {
|
|
57
|
-
type: QueryType.CreateTable;
|
|
58
|
-
table: Schema;
|
|
59
|
-
ifNotExists?: boolean;
|
|
60
|
-
}
|
|
61
|
-
function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
|
|
62
|
-
interface CreateIndex extends QueryBase {
|
|
63
|
-
type: QueryType.CreateIndex;
|
|
64
|
-
table: Schema;
|
|
65
|
-
index: IndexData;
|
|
66
|
-
ifNotExists?: boolean;
|
|
67
|
-
}
|
|
68
|
-
function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
|
|
69
|
-
interface DropIndex extends QueryBase {
|
|
70
|
-
type: QueryType.DropIndex;
|
|
71
|
-
table: Schema;
|
|
72
|
-
name: string;
|
|
73
|
-
ifExists?: boolean;
|
|
74
|
-
}
|
|
75
|
-
function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
|
|
76
|
-
interface Batch extends QueryBase {
|
|
77
|
-
type: QueryType.Batch;
|
|
78
|
-
queries: Array<Query<any>>;
|
|
79
|
-
}
|
|
80
|
-
function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
|
|
81
|
-
enum TransactionOperation {
|
|
82
|
-
Begin = "Begin",
|
|
83
|
-
Commit = "Commit",
|
|
84
|
-
Rollback = "Rollback"
|
|
85
|
-
}
|
|
86
|
-
interface Transaction extends QueryBase {
|
|
87
|
-
type: QueryType.Transaction;
|
|
88
|
-
id: string;
|
|
89
|
-
op: TransactionOperation;
|
|
90
|
-
}
|
|
91
|
-
function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
|
|
92
|
-
type RawReturn = 'row' | 'rows' | undefined;
|
|
93
|
-
interface Raw extends QueryBase {
|
|
94
|
-
type: QueryType.Raw;
|
|
95
|
-
expectedReturn?: 'row' | 'rows';
|
|
96
|
-
strings: ReadonlyArray<string>;
|
|
97
|
-
params: Array<any>;
|
|
98
|
-
}
|
|
99
|
-
function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
|
|
100
|
-
interface AlterTable extends QueryBase {
|
|
101
|
-
type: QueryType.AlterTable;
|
|
102
|
-
table: Schema;
|
|
103
|
-
alterColumn?: ColumnData;
|
|
104
|
-
addColumn?: ColumnData;
|
|
105
|
-
dropColumn?: string;
|
|
106
|
-
}
|
|
107
|
-
function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
|
|
108
|
-
}
|
|
1
|
+
import { ColumnData } from './Column';
|
|
2
|
+
import { ExprData } from './Expr';
|
|
3
|
+
import { IndexData } from './Index';
|
|
4
|
+
import { OrderBy } from './OrderBy';
|
|
5
|
+
import { Schema } from './Schema';
|
|
6
|
+
import { Target } from './Target';
|
|
7
|
+
export declare enum QueryType {
|
|
8
|
+
Insert = "Insert",
|
|
9
|
+
Select = "Select",
|
|
10
|
+
Update = "Update",
|
|
11
|
+
Delete = "Delete",
|
|
12
|
+
CreateTable = "CreateTable",
|
|
13
|
+
CreateIndex = "CreateIndex",
|
|
14
|
+
DropIndex = "DropIndex",
|
|
15
|
+
AlterTable = "AlterTable",
|
|
16
|
+
Batch = "Batch",
|
|
17
|
+
Transaction = "Transaction",
|
|
18
|
+
Raw = "Raw"
|
|
19
|
+
}
|
|
20
|
+
export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.CreateIndex | Query.DropIndex | Query.AlterTable | Query.Batch | Query.Transaction | Query.Raw;
|
|
21
|
+
export declare namespace Query {
|
|
22
|
+
interface QueryBase {
|
|
23
|
+
limit?: number;
|
|
24
|
+
offset?: number;
|
|
25
|
+
type: QueryType;
|
|
26
|
+
where?: ExprData;
|
|
27
|
+
orderBy?: Array<OrderBy>;
|
|
28
|
+
groupBy?: Array<ExprData>;
|
|
29
|
+
having?: ExprData;
|
|
30
|
+
selection?: ExprData;
|
|
31
|
+
singleResult?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface Insert extends QueryBase {
|
|
34
|
+
type: QueryType.Insert;
|
|
35
|
+
into: Schema;
|
|
36
|
+
data: Array<any>;
|
|
37
|
+
}
|
|
38
|
+
function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
|
|
39
|
+
interface Select extends QueryBase {
|
|
40
|
+
type: QueryType.Select;
|
|
41
|
+
selection: ExprData;
|
|
42
|
+
from: Target;
|
|
43
|
+
}
|
|
44
|
+
function Select(select: Omit<Select, 'type'>): Query.Select;
|
|
45
|
+
interface Update extends QueryBase {
|
|
46
|
+
type: QueryType.Update;
|
|
47
|
+
table: Schema;
|
|
48
|
+
set?: Record<string, any>;
|
|
49
|
+
}
|
|
50
|
+
function Update(update: Omit<Update, 'type'>): Query.Update;
|
|
51
|
+
interface Delete extends QueryBase {
|
|
52
|
+
type: QueryType.Delete;
|
|
53
|
+
table: Schema;
|
|
54
|
+
}
|
|
55
|
+
function Delete(del: Omit<Delete, 'type'>): Query.Delete;
|
|
56
|
+
interface CreateTable extends QueryBase {
|
|
57
|
+
type: QueryType.CreateTable;
|
|
58
|
+
table: Schema;
|
|
59
|
+
ifNotExists?: boolean;
|
|
60
|
+
}
|
|
61
|
+
function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
|
|
62
|
+
interface CreateIndex extends QueryBase {
|
|
63
|
+
type: QueryType.CreateIndex;
|
|
64
|
+
table: Schema;
|
|
65
|
+
index: IndexData;
|
|
66
|
+
ifNotExists?: boolean;
|
|
67
|
+
}
|
|
68
|
+
function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
|
|
69
|
+
interface DropIndex extends QueryBase {
|
|
70
|
+
type: QueryType.DropIndex;
|
|
71
|
+
table: Schema;
|
|
72
|
+
name: string;
|
|
73
|
+
ifExists?: boolean;
|
|
74
|
+
}
|
|
75
|
+
function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
|
|
76
|
+
interface Batch extends QueryBase {
|
|
77
|
+
type: QueryType.Batch;
|
|
78
|
+
queries: Array<Query<any>>;
|
|
79
|
+
}
|
|
80
|
+
function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
|
|
81
|
+
enum TransactionOperation {
|
|
82
|
+
Begin = "Begin",
|
|
83
|
+
Commit = "Commit",
|
|
84
|
+
Rollback = "Rollback"
|
|
85
|
+
}
|
|
86
|
+
interface Transaction extends QueryBase {
|
|
87
|
+
type: QueryType.Transaction;
|
|
88
|
+
id: string;
|
|
89
|
+
op: TransactionOperation;
|
|
90
|
+
}
|
|
91
|
+
function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
|
|
92
|
+
type RawReturn = 'row' | 'rows' | undefined;
|
|
93
|
+
interface Raw extends QueryBase {
|
|
94
|
+
type: QueryType.Raw;
|
|
95
|
+
expectedReturn?: 'row' | 'rows';
|
|
96
|
+
strings: ReadonlyArray<string>;
|
|
97
|
+
params: Array<any>;
|
|
98
|
+
}
|
|
99
|
+
function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
|
|
100
|
+
interface AlterTable extends QueryBase {
|
|
101
|
+
type: QueryType.AlterTable;
|
|
102
|
+
table: Schema;
|
|
103
|
+
alterColumn?: ColumnData;
|
|
104
|
+
addColumn?: ColumnData;
|
|
105
|
+
dropColumn?: string;
|
|
106
|
+
}
|
|
107
|
+
function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
|
|
108
|
+
}
|
package/dist/lib/Sanitizer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface Sanitizer {
|
|
2
|
-
escapeValue(value: any): string;
|
|
3
|
-
escapeIdentifier(ident: string): string;
|
|
4
|
-
}
|
|
1
|
+
export interface Sanitizer {
|
|
2
|
+
escapeValue(value: any): string;
|
|
3
|
+
escapeIdentifier(ident: string): string;
|
|
4
|
+
}
|
package/dist/lib/Schema.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { ColumnData } from './Column';
|
|
2
|
-
import { Formatter } from './Formatter';
|
|
3
|
-
import { IndexData } from './Index';
|
|
4
|
-
import { Query } from './Query';
|
|
5
|
-
export interface Schema {
|
|
6
|
-
name: string;
|
|
7
|
-
alias?: string;
|
|
8
|
-
columns: Record<string, ColumnData>;
|
|
9
|
-
indexes: Record<string, IndexData>;
|
|
10
|
-
}
|
|
11
|
-
export interface SchemaInstructions {
|
|
12
|
-
columns: Record<string, string>;
|
|
13
|
-
indexes: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
export declare namespace Schema {
|
|
16
|
-
function create(schema: Schema): Query.Batch;
|
|
17
|
-
function upgrade(formatter: Formatter, local: SchemaInstructions, schema: Schema): Array<Query>;
|
|
18
|
-
}
|
|
1
|
+
import { ColumnData } from './Column';
|
|
2
|
+
import { Formatter } from './Formatter';
|
|
3
|
+
import { IndexData } from './Index';
|
|
4
|
+
import { Query } from './Query';
|
|
5
|
+
export interface Schema {
|
|
6
|
+
name: string;
|
|
7
|
+
alias?: string;
|
|
8
|
+
columns: Record<string, ColumnData>;
|
|
9
|
+
indexes: Record<string, IndexData>;
|
|
10
|
+
}
|
|
11
|
+
export interface SchemaInstructions {
|
|
12
|
+
columns: Record<string, string>;
|
|
13
|
+
indexes: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export declare namespace Schema {
|
|
16
|
+
function create(schema: Schema): Query.Batch;
|
|
17
|
+
function upgrade(formatter: Formatter, local: SchemaInstructions, schema: Schema): Array<Query>;
|
|
18
|
+
}
|
package/dist/lib/Schema.js
CHANGED
|
@@ -27,7 +27,7 @@ var Schema;
|
|
|
27
27
|
} else if (!schemaCol) {
|
|
28
28
|
res.push(Query.AlterTable({ table: schema, dropColumn: columnName }));
|
|
29
29
|
} else {
|
|
30
|
-
const
|
|
30
|
+
const { sql: instruction } = formatter.formatColumn({ ...schemaCol, references: void 0 }).compile(formatter);
|
|
31
31
|
if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
|
|
32
32
|
res.push(Query.AlterTable({ table: schema, alterColumn: schemaCol }));
|
|
33
33
|
}
|
|
@@ -43,13 +43,13 @@ var Schema;
|
|
|
43
43
|
if (!localInstruction) {
|
|
44
44
|
res.push(Query.CreateIndex({ table: schema, index: schemaIndex }));
|
|
45
45
|
} else if (!schemaIndex) {
|
|
46
|
-
res.
|
|
46
|
+
res.unshift(Query.DropIndex({ table: schema, name: indexName }));
|
|
47
47
|
} else {
|
|
48
|
-
const
|
|
48
|
+
const { sql: instruction } = formatter.formatCreateIndex(
|
|
49
49
|
Query.CreateIndex({ table: schema, index: schemaIndex })
|
|
50
50
|
).compile(formatter);
|
|
51
51
|
if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
|
|
52
|
-
res.
|
|
52
|
+
res.unshift(Query.DropIndex({ table: schema, name: indexName }));
|
|
53
53
|
res.push(Query.CreateIndex({ table: schema, index: schemaIndex }));
|
|
54
54
|
}
|
|
55
55
|
}
|
package/dist/lib/Selection.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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
|
-
const __tableType: unique symbol;
|
|
9
|
-
const __cursorType: unique symbol;
|
|
10
|
-
type Infer<T> = T extends {
|
|
11
|
-
[__tableType](): infer K;
|
|
12
|
-
} ? K : T extends {
|
|
13
|
-
[__cursorType](): infer K;
|
|
14
|
-
} ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
|
|
15
|
-
[K in keyof T]: Infer<T[K]>;
|
|
16
|
-
} : T;
|
|
17
|
-
type With<A, B> = Expr<Combine<A, B>>;
|
|
18
|
-
type Combine<A, B> = Omit<A, keyof Infer<B>> & Infer<B>;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
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
|
+
const __tableType: unique symbol;
|
|
9
|
+
const __cursorType: unique symbol;
|
|
10
|
+
type Infer<T> = T extends {
|
|
11
|
+
[__tableType](): infer K;
|
|
12
|
+
} ? K : T extends {
|
|
13
|
+
[__cursorType](): infer K;
|
|
14
|
+
} ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
|
|
15
|
+
[K in keyof T]: Infer<T[K]>;
|
|
16
|
+
} : T;
|
|
17
|
+
type With<A, B> = Expr<Combine<A, B>>;
|
|
18
|
+
type Combine<A, B> = Omit<A, keyof Infer<B>> & Infer<B>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/dist/lib/Statement.d.ts
CHANGED
|
@@ -1,61 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export declare
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
import { ParamData } from './Param';
|
|
2
|
+
import { Sanitizer } from './Sanitizer';
|
|
3
|
+
declare enum TokenType {
|
|
4
|
+
Raw = "Raw",
|
|
5
|
+
Identifier = "Identifier",
|
|
6
|
+
Value = "Value",
|
|
7
|
+
Param = "Param",
|
|
8
|
+
Indent = "Indent",
|
|
9
|
+
Dedent = "Dedent"
|
|
10
|
+
}
|
|
11
|
+
declare class Token {
|
|
12
|
+
type: TokenType;
|
|
13
|
+
data: any;
|
|
14
|
+
constructor(type: TokenType, data: any);
|
|
15
|
+
static Raw(data: string): Token;
|
|
16
|
+
static Indent(): Token;
|
|
17
|
+
static Dedent(): Token;
|
|
18
|
+
static Identifier(data: string): Token;
|
|
19
|
+
static Value(data: any): Token;
|
|
20
|
+
static Param(name: string): Token;
|
|
21
|
+
}
|
|
22
|
+
export interface CompileOptions {
|
|
23
|
+
formatInline?: boolean;
|
|
24
|
+
spaces?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class Statement {
|
|
27
|
+
tokens: Array<Token>;
|
|
28
|
+
constructor(tokens: Array<Token>);
|
|
29
|
+
concat(...tokens: Array<Token | Statement>): Statement;
|
|
30
|
+
static create(from: string | Statement): Statement;
|
|
31
|
+
static tag(strings: ReadonlyArray<string>, params: Array<Statement>): Statement;
|
|
32
|
+
space(): Statement;
|
|
33
|
+
call(method: string, ...args: Array<Statement>): Statement;
|
|
34
|
+
addCall(method: string, ...args: Array<Statement>): Statement;
|
|
35
|
+
add(addition: undefined | string | Statement): Statement;
|
|
36
|
+
addLine(addition: undefined | string | Statement): Statement;
|
|
37
|
+
addIf(condition: any, addition: string | Statement | (() => string | Statement)): Statement;
|
|
38
|
+
indent(): Statement;
|
|
39
|
+
dedent(): Statement;
|
|
40
|
+
newline(ignore?: boolean): Statement;
|
|
41
|
+
identifier(name: string): Statement;
|
|
42
|
+
addIdentifier(name: string): Statement;
|
|
43
|
+
value(value: any): Statement;
|
|
44
|
+
addValue(value: any): Statement;
|
|
45
|
+
param(name: string): Statement;
|
|
46
|
+
addParam(name: string): Statement;
|
|
47
|
+
raw(query: string): Statement;
|
|
48
|
+
parenthesis(inner: string | Statement): Statement;
|
|
49
|
+
addParenthesis(stmnt: string | Statement): Statement;
|
|
50
|
+
separated(input: Array<Statement>, separator?: string): Statement;
|
|
51
|
+
addSeparated(input: Array<Statement>, separator?: string): Statement;
|
|
52
|
+
isEmpty(): boolean;
|
|
53
|
+
compile(sanitizer: Sanitizer, formatInline?: boolean): CompiledStatement;
|
|
54
|
+
}
|
|
55
|
+
export declare class CompiledStatement {
|
|
56
|
+
sql: string;
|
|
57
|
+
private paramData;
|
|
58
|
+
constructor(sql: string, paramData: Array<ParamData>);
|
|
59
|
+
params(input?: Record<string, any>): Array<any>;
|
|
60
|
+
toString(): string;
|
|
61
|
+
}
|
|
62
|
+
export declare function newline(): Statement;
|
|
63
|
+
export declare function raw(raw: string): Statement;
|
|
64
|
+
export declare function identifier(name: string): Statement;
|
|
65
|
+
export declare function value(value: any): Statement;
|
|
66
|
+
export declare function param(name: string): Statement;
|
|
67
|
+
export declare function empty(): Statement;
|
|
68
|
+
export declare function parenthesis(stmnt: Statement): Statement;
|
|
69
|
+
export declare function call(method: string, ...args: Array<Statement>): Statement;
|
|
70
|
+
export declare function separated(input: Array<Statement>, separator?: string): Statement;
|
|
71
|
+
export {};
|
package/dist/lib/Statement.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/lib/Statement.ts
|
|
2
|
+
import { ParamData, ParamType } from "./Param.js";
|
|
2
3
|
var Token = class {
|
|
3
4
|
constructor(type, data) {
|
|
4
5
|
this.type = type;
|
|
@@ -19,6 +20,9 @@ var Token = class {
|
|
|
19
20
|
static Value(data) {
|
|
20
21
|
return new Token("Value" /* Value */, data);
|
|
21
22
|
}
|
|
23
|
+
static Param(name) {
|
|
24
|
+
return new Token("Param" /* Param */, name);
|
|
25
|
+
}
|
|
22
26
|
};
|
|
23
27
|
var SEPARATE = ",";
|
|
24
28
|
var WHITESPACE = " ";
|
|
@@ -37,9 +41,12 @@ var Statement = class {
|
|
|
37
41
|
static create(from) {
|
|
38
42
|
return typeof from === "string" ? raw(from) : from;
|
|
39
43
|
}
|
|
40
|
-
static tag(strings,
|
|
44
|
+
static tag(strings, params) {
|
|
41
45
|
return new Statement(
|
|
42
|
-
strings.flatMap((s, i) =>
|
|
46
|
+
strings.flatMap((s, i) => {
|
|
47
|
+
const param2 = params[i];
|
|
48
|
+
return [Token.Raw(s)].concat(param2 ? param2.tokens : []);
|
|
49
|
+
})
|
|
43
50
|
);
|
|
44
51
|
}
|
|
45
52
|
space() {
|
|
@@ -93,6 +100,12 @@ var Statement = class {
|
|
|
93
100
|
addValue(value2) {
|
|
94
101
|
return this.space().value(value2);
|
|
95
102
|
}
|
|
103
|
+
param(name) {
|
|
104
|
+
return this.concat(Token.Param(name));
|
|
105
|
+
}
|
|
106
|
+
addParam(name) {
|
|
107
|
+
return this.space().param(name);
|
|
108
|
+
}
|
|
96
109
|
raw(query) {
|
|
97
110
|
if (!query)
|
|
98
111
|
return this;
|
|
@@ -118,7 +131,7 @@ var Statement = class {
|
|
|
118
131
|
return this.tokens.length === 0 || this.tokens.length === 1 && this.tokens[0].type === "Raw" /* Raw */ && this.tokens[0].data === "";
|
|
119
132
|
}
|
|
120
133
|
compile(sanitizer, formatInline = false) {
|
|
121
|
-
let sql = "",
|
|
134
|
+
let sql = "", paramData = [], indent = "";
|
|
122
135
|
for (const token of this.tokens) {
|
|
123
136
|
switch (token.type) {
|
|
124
137
|
case "Raw" /* Raw */:
|
|
@@ -135,9 +148,13 @@ var Statement = class {
|
|
|
135
148
|
sql += sanitizer.escapeValue(token.data);
|
|
136
149
|
} else {
|
|
137
150
|
sql += "?";
|
|
138
|
-
|
|
151
|
+
paramData.push(ParamData.Value(token.data ?? null));
|
|
139
152
|
}
|
|
140
153
|
break;
|
|
154
|
+
case "Param" /* Param */:
|
|
155
|
+
sql += "?";
|
|
156
|
+
paramData.push(ParamData.Named(token.data));
|
|
157
|
+
break;
|
|
141
158
|
case "Indent" /* Indent */:
|
|
142
159
|
indent += " ";
|
|
143
160
|
break;
|
|
@@ -146,7 +163,26 @@ var Statement = class {
|
|
|
146
163
|
break;
|
|
147
164
|
}
|
|
148
165
|
}
|
|
149
|
-
return
|
|
166
|
+
return new CompiledStatement(sql, paramData);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var CompiledStatement = class {
|
|
170
|
+
constructor(sql, paramData) {
|
|
171
|
+
this.sql = sql;
|
|
172
|
+
this.paramData = paramData;
|
|
173
|
+
}
|
|
174
|
+
params(input) {
|
|
175
|
+
return this.paramData.map((param2) => {
|
|
176
|
+
if (param2.type === ParamType.Named) {
|
|
177
|
+
if (input?.[param2.name] === void 0)
|
|
178
|
+
throw new TypeError(`Missing parameter ${param2.name}`);
|
|
179
|
+
return input[param2.name];
|
|
180
|
+
}
|
|
181
|
+
return param2.value;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
toString() {
|
|
185
|
+
return this.sql;
|
|
150
186
|
}
|
|
151
187
|
};
|
|
152
188
|
function newline() {
|
|
@@ -161,6 +197,9 @@ function identifier(name) {
|
|
|
161
197
|
function value(value2) {
|
|
162
198
|
return new Statement([Token.Value(value2)]);
|
|
163
199
|
}
|
|
200
|
+
function param(name) {
|
|
201
|
+
return new Statement([Token.Param(name)]);
|
|
202
|
+
}
|
|
164
203
|
function empty() {
|
|
165
204
|
return new Statement([]);
|
|
166
205
|
}
|
|
@@ -174,11 +213,13 @@ function separated(input, separator = SEPARATE) {
|
|
|
174
213
|
return empty().separated(input, separator);
|
|
175
214
|
}
|
|
176
215
|
export {
|
|
216
|
+
CompiledStatement,
|
|
177
217
|
Statement,
|
|
178
218
|
call,
|
|
179
219
|
empty,
|
|
180
220
|
identifier,
|
|
181
221
|
newline,
|
|
222
|
+
param,
|
|
182
223
|
parenthesis,
|
|
183
224
|
raw,
|
|
184
225
|
separated,
|