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
@@ -1,15 +1,20 @@
1
- export declare enum ParamType {
2
- Value = "Value",
3
- Named = "Named"
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
- };
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
  };
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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 [instruction] = formatter.formatColumn({ ...schemaCol, references: void 0 }).compile(formatter);
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.push(Query.DropIndex({ table: schema, name: indexName }));
46
+ res.unshift(Query.DropIndex({ table: schema, name: indexName }));
47
47
  } else {
48
- const [instruction] = formatter.formatCreateIndex(
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.push(Query.DropIndex({ table: schema, name: indexName }));
52
+ res.unshift(Query.DropIndex({ table: schema, name: indexName }));
53
53
  res.push(Query.CreateIndex({ table: schema, index: schemaIndex }));
54
54
  }
55
55
  }
@@ -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 {};
@@ -1,61 +1,71 @@
1
- import { Sanitizer } from './Sanitizer';
2
- declare 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 interface CompileOptions {
20
- formatInline?: boolean;
21
- spaces?: number;
22
- }
23
- export declare class Statement {
24
- tokens: Array<Token>;
25
- constructor(tokens: Array<Token>);
26
- concat(...tokens: Array<Token | Statement>): Statement;
27
- static create(from: string | Statement): Statement;
28
- static tag(strings: ReadonlyArray<string>, ...params: Array<any>): Statement;
29
- space(): Statement;
30
- call(method: string, ...args: Array<Statement>): Statement;
31
- addCall(method: string, ...args: Array<Statement>): Statement;
32
- add(addition: undefined | string | Statement): Statement;
33
- addLine(addition: undefined | string | Statement): Statement;
34
- addIf(condition: any, addition: string | Statement | (() => string | Statement)): Statement;
35
- indent(): Statement;
36
- dedent(): Statement;
37
- newline(ignore?: boolean): Statement;
38
- identifier(name: string): Statement;
39
- addIdentifier(name: string): Statement;
40
- value(value: any): Statement;
41
- addValue(value: any): Statement;
42
- raw(query: string): Statement;
43
- parenthesis(inner: string | Statement): Statement;
44
- addParenthesis(stmnt: string | Statement): Statement;
45
- separated(input: Array<Statement>, separator?: string): Statement;
46
- addSeparated(input: Array<Statement>, separator?: string): Statement;
47
- isEmpty(): boolean;
48
- compile(sanitizer: Sanitizer, formatInline?: boolean): Statement.Compiled;
49
- }
50
- export declare namespace Statement {
51
- type Compiled = [sql: string, params: Array<any>];
52
- }
53
- export declare function newline(): Statement;
54
- export declare function raw(raw: string): Statement;
55
- export declare function identifier(name: string): Statement;
56
- export declare function value(value: any): Statement;
57
- export declare function empty(): Statement;
58
- export declare function parenthesis(stmnt: Statement): Statement;
59
- export declare function call(method: string, ...args: Array<Statement>): Statement;
60
- export declare function separated(input: Array<Statement>, separator?: string): Statement;
61
- export {};
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 {};
@@ -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, ...params) {
44
+ static tag(strings, params) {
41
45
  return new Statement(
42
- strings.flatMap((s, i) => [Token.Raw(s), Token.Value(params[i])]).slice(0, -1)
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 = "", params = [], indent = "";
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
- params.push(token.data === void 0 ? null : token.data);
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 [sql, params];
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,