rado 0.1.62 → 0.1.64

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 (151) hide show
  1. package/dist/define/Column.d.ts +58 -58
  2. package/dist/define/Cursor.d.ts +87 -87
  3. package/dist/define/Cursor.js +8 -0
  4. package/dist/define/Expr.d.ts +173 -172
  5. package/dist/define/Expr.js +44 -41
  6. package/dist/define/Fields.d.ts +13 -13
  7. package/dist/define/Functions.d.ts +5 -5
  8. package/dist/define/Id.d.ts +3 -3
  9. package/dist/define/Index.d.ts +17 -17
  10. package/dist/define/Ops.d.ts +9 -7
  11. package/dist/define/Ops.js +8 -0
  12. package/dist/define/OrderBy.d.ts +9 -9
  13. package/dist/define/Param.d.ts +15 -15
  14. package/dist/define/Query.d.ts +109 -109
  15. package/dist/define/Schema.d.ts +18 -18
  16. package/dist/define/Selection.d.ts +20 -20
  17. package/dist/define/Table.d.ts +62 -62
  18. package/dist/define/Target.d.ts +38 -38
  19. package/dist/define/Update.d.ts +4 -4
  20. package/dist/driver/better-sqlite3.d.ts +15 -15
  21. package/dist/driver/bun-sqlite.d.ts +18 -18
  22. package/dist/driver/sql.js.d.ts +15 -15
  23. package/dist/driver/sqlite3.d.ts +18 -18
  24. package/dist/index.d.ts +21 -21
  25. package/dist/lib/Driver.d.ts +110 -110
  26. package/dist/lib/Formatter.d.ts +81 -81
  27. package/dist/lib/Formatter.js +18 -12
  28. package/dist/lib/Sanitizer.d.ts +5 -5
  29. package/dist/lib/SqlError.d.ts +3 -3
  30. package/dist/lib/Statement.d.ts +33 -33
  31. package/dist/sqlite/SqliteFormatter.d.ts +11 -11
  32. package/dist/sqlite/SqliteFunctions.d.ts +165 -165
  33. package/dist/sqlite/SqliteSchema.d.ts +25 -25
  34. package/dist/sqlite.d.ts +2 -2
  35. package/package.json +60 -60
  36. package/dist/CPU.20230126.092143.12244.0.001.cpuprofile +0 -1
  37. package/dist/Column.d.ts +0 -54
  38. package/dist/Column.js +0 -63
  39. package/dist/Cursor.d.ts +0 -77
  40. package/dist/Cursor.js +0 -221
  41. package/dist/Driver.d.ts +0 -89
  42. package/dist/Driver.js +0 -262
  43. package/dist/Expr.d.ts +0 -149
  44. package/dist/Expr.js +0 -284
  45. package/dist/Fields.d.ts +0 -11
  46. package/dist/Fields.js +0 -0
  47. package/dist/Formatter.d.ts +0 -55
  48. package/dist/Formatter.js +0 -496
  49. package/dist/Functions.d.ts +0 -7
  50. package/dist/Functions.js +0 -11
  51. package/dist/Id.d.ts +0 -3
  52. package/dist/Id.js +0 -0
  53. package/dist/Ops.d.ts +0 -8
  54. package/dist/Ops.js +0 -45
  55. package/dist/OrderBy.d.ts +0 -9
  56. package/dist/OrderBy.js +0 -9
  57. package/dist/Param.d.ts +0 -15
  58. package/dist/Param.js +0 -18
  59. package/dist/Query.d.ts +0 -107
  60. package/dist/Query.js +0 -74
  61. package/dist/Sanitizer.d.ts +0 -4
  62. package/dist/Sanitizer.js +0 -0
  63. package/dist/Schema.d.ts +0 -23
  64. package/dist/Schema.js +0 -60
  65. package/dist/Selection.d.ts +0 -20
  66. package/dist/Selection.js +0 -7
  67. package/dist/Statement.d.ts +0 -57
  68. package/dist/Statement.js +0 -184
  69. package/dist/Table.d.ts +0 -56
  70. package/dist/Table.js +0 -104
  71. package/dist/Target.d.ts +0 -30
  72. package/dist/Target.js +0 -37
  73. package/dist/Update.d.ts +0 -4
  74. package/dist/Update.js +0 -0
  75. package/dist/lib/Column.d.ts +0 -57
  76. package/dist/lib/Column.js +0 -63
  77. package/dist/lib/Cursor.d.ts +0 -79
  78. package/dist/lib/Cursor.js +0 -231
  79. package/dist/lib/Expr.d.ts +0 -154
  80. package/dist/lib/Expr.js +0 -284
  81. package/dist/lib/Fields.d.ts +0 -13
  82. package/dist/lib/Fields.js +0 -0
  83. package/dist/lib/Functions.d.ts +0 -5
  84. package/dist/lib/Functions.js +0 -11
  85. package/dist/lib/Id.d.ts +0 -3
  86. package/dist/lib/Id.js +0 -0
  87. package/dist/lib/Index.d.ts +0 -17
  88. package/dist/lib/Index.js +0 -20
  89. package/dist/lib/Ops.d.ts +0 -8
  90. package/dist/lib/Ops.js +0 -45
  91. package/dist/lib/OrderBy.d.ts +0 -9
  92. package/dist/lib/OrderBy.js +0 -9
  93. package/dist/lib/Param.d.ts +0 -20
  94. package/dist/lib/Param.js +0 -27
  95. package/dist/lib/Query.d.ts +0 -109
  96. package/dist/lib/Query.js +0 -74
  97. package/dist/lib/Schema.d.ts +0 -18
  98. package/dist/lib/Schema.js +0 -67
  99. package/dist/lib/Selection.d.ts +0 -20
  100. package/dist/lib/Selection.js +0 -7
  101. package/dist/lib/Table.d.ts +0 -62
  102. package/dist/lib/Table.js +0 -130
  103. package/dist/lib/Target.d.ts +0 -30
  104. package/dist/lib/Target.js +0 -37
  105. package/dist/lib/Update.d.ts +0 -4
  106. package/dist/lib/Update.js +0 -0
  107. package/dist/sqlite/index.d.ts +0 -2
  108. package/dist/sqlite/index.js +0 -3
  109. package/dist/src/driver/better-sqlite3.js +0 -49
  110. package/dist/src/driver/sql.js.js +0 -66
  111. package/dist/src/driver/sqlite3.js +0 -87
  112. package/dist/src/index.js +0 -24
  113. package/dist/src/lib/Column.js +0 -63
  114. package/dist/src/lib/Cursor.js +0 -231
  115. package/dist/src/lib/Driver.js +0 -316
  116. package/dist/src/lib/Expr.js +0 -284
  117. package/dist/src/lib/Fields.js +0 -0
  118. package/dist/src/lib/Formatter.js +0 -625
  119. package/dist/src/lib/Functions.js +0 -11
  120. package/dist/src/lib/Id.js +0 -0
  121. package/dist/src/lib/Index.js +0 -20
  122. package/dist/src/lib/Ops.js +0 -45
  123. package/dist/src/lib/OrderBy.js +0 -9
  124. package/dist/src/lib/Param.js +0 -27
  125. package/dist/src/lib/Query.js +0 -74
  126. package/dist/src/lib/Sanitizer.js +0 -0
  127. package/dist/src/lib/Schema.js +0 -67
  128. package/dist/src/lib/Selection.js +0 -7
  129. package/dist/src/lib/Statement.js +0 -103
  130. package/dist/src/lib/Table.js +0 -130
  131. package/dist/src/lib/Target.js +0 -37
  132. package/dist/src/lib/Update.js +0 -0
  133. package/dist/src/sqlite/SqliteFormatter.js +0 -67
  134. package/dist/src/sqlite/SqliteFunctions.js +0 -146
  135. package/dist/src/sqlite/SqliteSchema.js +0 -47
  136. package/dist/src/sqlite.js +0 -3
  137. package/dist/test/DbSuite.js +0 -28
  138. package/dist/test/TSTestTypes.js +0 -6
  139. package/dist/test/TestBasic.js +0 -172
  140. package/dist/test/TestExtend.js +0 -68
  141. package/dist/test/TestFts5.js +0 -34
  142. package/dist/test/TestFunctions.js +0 -28
  143. package/dist/test/TestJoins.js +0 -34
  144. package/dist/test/TestJson.js +0 -33
  145. package/dist/test/TestPrepare.js +0 -27
  146. package/dist/test/TestRawSql.js +0 -31
  147. package/dist/test/TestSchema.js +0 -69
  148. package/dist/test/TestSubQueries.js +0 -79
  149. package/dist/test/TestTransaction.js +0 -54
  150. package/dist/test/TestUpdate.js +0 -95
  151. package/dist/test/index.js +0 -14
package/dist/index.d.ts CHANGED
@@ -1,21 +1,21 @@
1
- export * from './define/Column';
2
- export * from './define/Cursor';
3
- export * from './define/Expr';
4
- export * from './define/Fields';
5
- export * from './define/Functions';
6
- export * from './define/Id';
7
- export * from './define/Index';
8
- export * from './define/Ops';
9
- export * from './define/OrderBy';
10
- export * from './define/Param';
11
- export * from './define/Query';
12
- export * from './define/Schema';
13
- export * from './define/Selection';
14
- export * from './define/Table';
15
- export * from './define/Target';
16
- export * from './define/Update';
17
- export type { Driver } from './lib/Driver';
18
- export type { FormatContext, Formatter } from './lib/Formatter';
19
- export type { Sanitizer } from './lib/Sanitizer';
20
- export * from './lib/SqlError';
21
- export type { Statement } from './lib/Statement';
1
+ export * from './define/Column';
2
+ export * from './define/Cursor';
3
+ export * from './define/Expr';
4
+ export * from './define/Fields';
5
+ export * from './define/Functions';
6
+ export * from './define/Id';
7
+ export * from './define/Index';
8
+ export * from './define/Ops';
9
+ export * from './define/OrderBy';
10
+ export * from './define/Param';
11
+ export * from './define/Query';
12
+ export * from './define/Schema';
13
+ export * from './define/Selection';
14
+ export * from './define/Table';
15
+ export * from './define/Target';
16
+ export * from './define/Update';
17
+ export type { Driver } from './lib/Driver';
18
+ export type { FormatContext, Formatter } from './lib/Formatter';
19
+ export type { Sanitizer } from './lib/Sanitizer';
20
+ export * from './lib/SqlError';
21
+ export type { Statement } from './lib/Statement';
@@ -1,110 +1,110 @@
1
- import { Cursor } from '../define/Cursor';
2
- import { Expr } from '../define/Expr';
3
- import { Query } from '../define/Query';
4
- import { SchemaInstructions } from '../define/Schema';
5
- import { Table } from '../define/Table';
6
- import { Formatter } from './Formatter';
7
- import { Statement } from './Statement';
8
- declare class Callable extends Function {
9
- constructor(fn: Function);
10
- }
11
- declare abstract class DriverBase extends Callable {
12
- formatter: Formatter;
13
- constructor(formatter: Formatter);
14
- compile<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): [Query<T>, Statement];
15
- all(...args: Array<any>): any;
16
- get(...args: Array<any>): any;
17
- sql(strings: TemplateStringsArray, ...params: Array<any>): Cursor<unknown>;
18
- executeTemplate(expectedReturn: Query.RawReturn, strings: TemplateStringsArray, ...params: Array<any>): any;
19
- abstract executeQuery(query: Query<any>): any;
20
- }
21
- type ParamTypes<Params extends [...any[]]> = {
22
- [K in keyof Params]: Params[K] extends Expr<infer T> ? T : never;
23
- } & {
24
- length: Params['length'];
25
- };
26
- interface SyncDriver {
27
- <T>(query: Cursor<T>): T;
28
- <T>(...queries: Array<Cursor<any>>): T;
29
- (strings: TemplateStringsArray, ...values: any[]): any;
30
- }
31
- declare abstract class SyncDriver extends DriverBase {
32
- transactionId: number;
33
- abstract prepareStatement(stmt: Statement, discardAfter: boolean): SyncPreparedStatement;
34
- abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
35
- prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => R;
36
- migrateSchema(...tables: Array<Table<any>>): unknown;
37
- executeQuery<T>(query: Query<T>, stmt?: SyncPreparedStatement, params?: Array<any>): T;
38
- all<T>(cursor: Cursor.SelectSingle<T>): Array<T>;
39
- all<T>(cursor: Cursor<T>): T;
40
- all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
41
- get<T>(cursor: Cursor.SelectMultiple<T>): T | null;
42
- get<T>(cursor: Cursor<T>): T;
43
- get<T>(strings: TemplateStringsArray, ...params: Array<any>): T;
44
- iterate<T>(cursor: Cursor.SelectMultiple<T>): Iterable<T>;
45
- transaction<T>(run: (query: SyncDriver) => T): T;
46
- toAsync(): SyncWrapper;
47
- }
48
- interface SyncPreparedStatement {
49
- run(params?: Array<any>): {
50
- rowsAffected: number;
51
- };
52
- iterate<T>(params?: Array<any>): Iterable<T>;
53
- all<T>(params?: Array<any>): Array<T>;
54
- get<T>(params?: Array<any>): T;
55
- execute(params?: Array<any>): void;
56
- }
57
- interface AsyncDriver {
58
- <T>(query: Cursor<T>): Promise<T>;
59
- <T>(...queries: Array<Cursor<any>>): Promise<T>;
60
- (strings: TemplateStringsArray, ...values: any[]): Promise<any>;
61
- }
62
- declare abstract class AsyncDriver extends DriverBase {
63
- transactionId: number;
64
- abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
65
- abstract prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
66
- abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
67
- prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => Promise<R>;
68
- migrateSchema(...tables: Array<Table<any>>): Promise<unknown>;
69
- executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
70
- all<T>(cursor: Cursor.SelectSingle<T>): Promise<Array<T>>;
71
- all<T>(cursor: Cursor<T>): Promise<T>;
72
- all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
73
- get<T>(cursor: Cursor.SelectMultiple<T>): Promise<T | null>;
74
- get<T>(cursor: Cursor<T>): Promise<T>;
75
- get<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<T>;
76
- iterate<T>(cursor: Cursor.SelectMultiple<T>): AsyncIterable<T>;
77
- transaction<T>(run: (query: AsyncDriver) => T): Promise<T>;
78
- }
79
- declare class SyncWrapper extends AsyncDriver {
80
- private sync;
81
- lock: Promise<void> | undefined;
82
- constructor(sync: SyncDriver);
83
- executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
84
- prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
85
- schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
86
- isolate(): [connection: AsyncDriver, release: () => Promise<void>];
87
- }
88
- interface AsyncPreparedStatement {
89
- run(params?: Array<any>): Promise<{
90
- rowsAffected: number;
91
- }>;
92
- iterate<T>(params?: Array<any>): AsyncIterable<T>;
93
- all<T>(params?: Array<any>): Promise<Array<T>>;
94
- get<T>(params?: Array<any>): Promise<T>;
95
- execute(params?: Array<any>): Promise<void>;
96
- }
97
- export type Driver = SyncDriver | AsyncDriver;
98
- export declare namespace Driver {
99
- type Sync = SyncDriver;
100
- const Sync: typeof SyncDriver;
101
- namespace Sync {
102
- type PreparedStatement = SyncPreparedStatement;
103
- }
104
- type Async = AsyncDriver;
105
- const Async: typeof AsyncDriver;
106
- namespace Async {
107
- type PreparedStatement = AsyncPreparedStatement;
108
- }
109
- }
110
- export {};
1
+ import { Cursor } from '../define/Cursor';
2
+ import { Expr } from '../define/Expr';
3
+ import { Query } from '../define/Query';
4
+ import { SchemaInstructions } from '../define/Schema';
5
+ import { Table } from '../define/Table';
6
+ import { Formatter } from './Formatter';
7
+ import { Statement } from './Statement';
8
+ declare class Callable extends Function {
9
+ constructor(fn: Function);
10
+ }
11
+ declare abstract class DriverBase extends Callable {
12
+ formatter: Formatter;
13
+ constructor(formatter: Formatter);
14
+ compile<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): [Query<T>, Statement];
15
+ all(...args: Array<any>): any;
16
+ get(...args: Array<any>): any;
17
+ sql(strings: TemplateStringsArray, ...params: Array<any>): Cursor<unknown>;
18
+ executeTemplate(expectedReturn: Query.RawReturn, strings: TemplateStringsArray, ...params: Array<any>): any;
19
+ abstract executeQuery(query: Query<any>): any;
20
+ }
21
+ type ParamTypes<Params extends [...any[]]> = {
22
+ [K in keyof Params]: Params[K] extends Expr<infer T> ? T : never;
23
+ } & {
24
+ length: Params['length'];
25
+ };
26
+ interface SyncDriver {
27
+ <T>(query: Cursor<T>): T;
28
+ <T>(...queries: Array<Cursor<any>>): T;
29
+ (strings: TemplateStringsArray, ...values: any[]): any;
30
+ }
31
+ declare abstract class SyncDriver extends DriverBase {
32
+ transactionId: number;
33
+ abstract prepareStatement(stmt: Statement, discardAfter: boolean): SyncPreparedStatement;
34
+ abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
35
+ prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => R;
36
+ migrateSchema(...tables: Array<Table<any>>): unknown;
37
+ executeQuery<T>(query: Query<T>, stmt?: SyncPreparedStatement, params?: Array<any>): T;
38
+ all<T>(cursor: Cursor.SelectSingle<T>): Array<T>;
39
+ all<T>(cursor: Cursor<T>): T;
40
+ all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
41
+ get<T>(cursor: Cursor.SelectMultiple<T>): T | null;
42
+ get<T>(cursor: Cursor<T>): T;
43
+ get<T>(strings: TemplateStringsArray, ...params: Array<any>): T;
44
+ iterate<T>(cursor: Cursor.SelectMultiple<T>): Iterable<T>;
45
+ transaction<T>(run: (query: SyncDriver) => T): T;
46
+ toAsync(): SyncWrapper;
47
+ }
48
+ interface SyncPreparedStatement {
49
+ run(params?: Array<any>): {
50
+ rowsAffected: number;
51
+ };
52
+ iterate<T>(params?: Array<any>): Iterable<T>;
53
+ all<T>(params?: Array<any>): Array<T>;
54
+ get<T>(params?: Array<any>): T;
55
+ execute(params?: Array<any>): void;
56
+ }
57
+ interface AsyncDriver {
58
+ <T>(query: Cursor<T>): Promise<T>;
59
+ <T>(...queries: Array<Cursor<any>>): Promise<T>;
60
+ (strings: TemplateStringsArray, ...values: any[]): Promise<any>;
61
+ }
62
+ declare abstract class AsyncDriver extends DriverBase {
63
+ transactionId: number;
64
+ abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
65
+ abstract prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
66
+ abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
67
+ prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => Promise<R>;
68
+ migrateSchema(...tables: Array<Table<any>>): Promise<unknown>;
69
+ executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
70
+ all<T>(cursor: Cursor.SelectSingle<T>): Promise<Array<T>>;
71
+ all<T>(cursor: Cursor<T>): Promise<T>;
72
+ all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
73
+ get<T>(cursor: Cursor.SelectMultiple<T>): Promise<T | null>;
74
+ get<T>(cursor: Cursor<T>): Promise<T>;
75
+ get<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<T>;
76
+ iterate<T>(cursor: Cursor.SelectMultiple<T>): AsyncIterable<T>;
77
+ transaction<T>(run: (query: AsyncDriver) => T): Promise<T>;
78
+ }
79
+ declare class SyncWrapper extends AsyncDriver {
80
+ private sync;
81
+ lock: Promise<void> | undefined;
82
+ constructor(sync: SyncDriver);
83
+ executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
84
+ prepareStatement(stmt: Statement, discardAfter: boolean): AsyncPreparedStatement;
85
+ schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
86
+ isolate(): [connection: AsyncDriver, release: () => Promise<void>];
87
+ }
88
+ interface AsyncPreparedStatement {
89
+ run(params?: Array<any>): Promise<{
90
+ rowsAffected: number;
91
+ }>;
92
+ iterate<T>(params?: Array<any>): AsyncIterable<T>;
93
+ all<T>(params?: Array<any>): Promise<Array<T>>;
94
+ get<T>(params?: Array<any>): Promise<T>;
95
+ execute(params?: Array<any>): Promise<void>;
96
+ }
97
+ export type Driver = SyncDriver | AsyncDriver;
98
+ export declare namespace Driver {
99
+ type Sync = SyncDriver;
100
+ const Sync: typeof SyncDriver;
101
+ namespace Sync {
102
+ type PreparedStatement = SyncPreparedStatement;
103
+ }
104
+ type Async = AsyncDriver;
105
+ const Async: typeof AsyncDriver;
106
+ namespace Async {
107
+ type PreparedStatement = AsyncPreparedStatement;
108
+ }
109
+ }
110
+ export {};
@@ -1,81 +1,81 @@
1
- import { ColumnData, ColumnType } from '../define/Column';
2
- import { ExprData } from '../define/Expr';
3
- import { OrderBy } from '../define/OrderBy';
4
- import { Query } from '../define/Query';
5
- import { Target } from '../define/Target';
6
- import { Sanitizer } from './Sanitizer';
7
- import { Statement, StatementOptions } from './Statement';
8
- export interface FormatContext {
9
- stmt: Statement;
10
- nameResult?: string;
11
- /** Skip prefixing fields with their table name */
12
- skipTableName?: boolean;
13
- /**
14
- * In SQLite table names are used as expressions in the FTS5 plugin.
15
- * To distinguish between formatting a row of the table and just the table name
16
- * this flag can be used.
17
- **/
18
- tableAsExpr?: boolean;
19
- /** Inline all parameters */
20
- forceInline?: boolean;
21
- formatAsJson?: boolean;
22
- formatAsInsert?: boolean;
23
- formatAsIn?: boolean;
24
- topLevel?: boolean;
25
- }
26
- type FormatSubject = (stmt: Statement, mkSubject: () => void) => void;
27
- export interface CompileOptions extends Partial<FormatContext>, StatementOptions {
28
- }
29
- export declare abstract class Formatter implements Sanitizer {
30
- constructor();
31
- abstract escapeValue(value: any): string;
32
- abstract escapeIdentifier(ident: string): string;
33
- abstract formatParamValue(paramValue: any): any;
34
- abstract formatAccess(ctx: FormatContext, mkSubject: () => void, field: string): Statement;
35
- compile<T>(query: Query<T>, options?: CompileOptions): Statement;
36
- createContext(options?: CompileOptions): {
37
- stmt: Statement;
38
- nameResult?: string | undefined;
39
- skipTableName?: boolean | undefined;
40
- tableAsExpr?: boolean | undefined;
41
- forceInline?: boolean | undefined;
42
- formatAsJson?: boolean | undefined;
43
- formatAsInsert?: boolean | undefined;
44
- formatAsIn?: boolean | undefined;
45
- topLevel?: boolean | undefined;
46
- skipNewlines?: boolean | undefined;
47
- };
48
- format<T>(ctx: FormatContext, query: Query<T>): Statement;
49
- formatSelect({ topLevel, ...ctx }: FormatContext, query: Query.Select): Statement;
50
- formatInsert(ctx: FormatContext, query: Query.Insert): Statement;
51
- formatUpdate(ctx: FormatContext, query: Query.Update): Statement;
52
- formatDelete(ctx: FormatContext, query: Query.Delete): Statement;
53
- formatCreateTable(ctx: FormatContext, query: Query.CreateTable): Statement;
54
- formatCreateIndex(ctx: FormatContext, query: Query.CreateIndex): Statement;
55
- formatDropIndex(ctx: FormatContext, query: Query.DropIndex): Statement;
56
- formatAlterTable(ctx: FormatContext, query: Query.AlterTable): Statement;
57
- formatTransaction(ctx: FormatContext, { op, id }: Query.Transaction): Statement;
58
- formatBatch(ctx: FormatContext, { queries }: Query.Batch): Statement;
59
- formatRaw(ctx: FormatContext, { strings, params }: Query.Raw): Statement;
60
- formatColumn(ctx: FormatContext, column: ColumnData): Statement;
61
- formatContraintReference(ctx: FormatContext, reference: ExprData): Statement;
62
- formatType(ctx: FormatContext, type: ColumnType): Statement;
63
- formatInsertRow(ctx: FormatContext, columns: Record<string, ColumnData>, row: Record<string, any>): Statement;
64
- formatColumnValue(ctx: FormatContext, column: ColumnData, columnValue: any): Statement;
65
- formatTarget(ctx: FormatContext, target: Target): Statement;
66
- formatWhere({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
67
- formatHaving({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
68
- formatGroupBy(ctx: FormatContext, groupBy: Array<ExprData> | undefined): Statement;
69
- formatOrderBy(ctx: FormatContext, orderBy: Array<OrderBy> | undefined): Statement;
70
- formatLimit(ctx: FormatContext, { limit, offset, singleResult }: Query.QueryBase): Statement;
71
- formatSelection(ctx: FormatContext, selection: ExprData, formatSubject?: FormatSubject): Statement;
72
- formatExprJson(ctx: FormatContext, expr: ExprData): Statement;
73
- formatExprValue(ctx: FormatContext, expr: ExprData): Statement;
74
- retrieveField(expr: ExprData, field: string): ExprData | undefined;
75
- formatField(ctx: FormatContext, expr: ExprData, field: string): Statement;
76
- formatString(ctx: FormatContext, input: string): Statement;
77
- formatInlineValue(ctx: FormatContext, rawValue: any): Statement;
78
- formatValue(ctx: FormatContext, rawValue: any): Statement;
79
- formatExpr({ formatAsIn, ...ctx }: FormatContext, expr: ExprData): Statement;
80
- }
81
- export {};
1
+ import { ColumnData, ColumnType } from '../define/Column';
2
+ import { ExprData } from '../define/Expr';
3
+ import { OrderBy } from '../define/OrderBy';
4
+ import { Query } from '../define/Query';
5
+ import { Target } from '../define/Target';
6
+ import { Sanitizer } from './Sanitizer';
7
+ import { Statement, StatementOptions } from './Statement';
8
+ export interface FormatContext {
9
+ stmt: Statement;
10
+ nameResult?: string;
11
+ /** Skip prefixing fields with their table name */
12
+ skipTableName?: boolean;
13
+ /**
14
+ * In SQLite table names are used as expressions in the FTS5 plugin.
15
+ * To distinguish between formatting a row of the table and just the table name
16
+ * this flag can be used.
17
+ **/
18
+ tableAsExpr?: boolean;
19
+ /** Inline all parameters */
20
+ forceInline?: boolean;
21
+ formatAsJson?: boolean;
22
+ formatAsInsert?: boolean;
23
+ formatAsIn?: boolean;
24
+ topLevel?: boolean;
25
+ }
26
+ type FormatSubject = (stmt: Statement, mkSubject: () => void) => void;
27
+ export interface CompileOptions extends Partial<FormatContext>, StatementOptions {
28
+ }
29
+ export declare abstract class Formatter implements Sanitizer {
30
+ constructor();
31
+ abstract escapeValue(value: any): string;
32
+ abstract escapeIdentifier(ident: string): string;
33
+ abstract formatParamValue(paramValue: any): any;
34
+ abstract formatAccess(ctx: FormatContext, mkSubject: () => void, field: string): Statement;
35
+ compile<T>(query: Query<T>, options?: CompileOptions): Statement;
36
+ createContext(options?: CompileOptions): {
37
+ stmt: Statement;
38
+ nameResult?: string | undefined;
39
+ skipTableName?: boolean | undefined;
40
+ tableAsExpr?: boolean | undefined;
41
+ forceInline?: boolean | undefined;
42
+ formatAsJson?: boolean | undefined;
43
+ formatAsInsert?: boolean | undefined;
44
+ formatAsIn?: boolean | undefined;
45
+ topLevel?: boolean | undefined;
46
+ skipNewlines?: boolean | undefined;
47
+ };
48
+ format<T>(ctx: FormatContext, query: Query<T>): Statement;
49
+ formatSelect({ topLevel, ...ctx }: FormatContext, query: Query.Select): Statement;
50
+ formatInsert(ctx: FormatContext, query: Query.Insert): Statement;
51
+ formatUpdate(ctx: FormatContext, query: Query.Update): Statement;
52
+ formatDelete(ctx: FormatContext, query: Query.Delete): Statement;
53
+ formatCreateTable(ctx: FormatContext, query: Query.CreateTable): Statement;
54
+ formatCreateIndex(ctx: FormatContext, query: Query.CreateIndex): Statement;
55
+ formatDropIndex(ctx: FormatContext, query: Query.DropIndex): Statement;
56
+ formatAlterTable(ctx: FormatContext, query: Query.AlterTable): Statement;
57
+ formatTransaction(ctx: FormatContext, { op, id }: Query.Transaction): Statement;
58
+ formatBatch(ctx: FormatContext, { queries }: Query.Batch): Statement;
59
+ formatRaw(ctx: FormatContext, { strings, params }: Query.Raw): Statement;
60
+ formatColumn(ctx: FormatContext, column: ColumnData): Statement;
61
+ formatContraintReference(ctx: FormatContext, reference: ExprData): Statement;
62
+ formatType(ctx: FormatContext, type: ColumnType): Statement;
63
+ formatInsertRow(ctx: FormatContext, columns: Record<string, ColumnData>, row: Record<string, any>): Statement;
64
+ formatColumnValue(ctx: FormatContext, column: ColumnData, columnValue: any): Statement;
65
+ formatTarget(ctx: FormatContext, target: Target): Statement;
66
+ formatWhere({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
67
+ formatHaving({ topLevel, ...ctx }: FormatContext, expr: ExprData | undefined): Statement;
68
+ formatGroupBy(ctx: FormatContext, groupBy: Array<ExprData> | undefined): Statement;
69
+ formatOrderBy(ctx: FormatContext, orderBy: Array<OrderBy> | undefined): Statement;
70
+ formatLimit(ctx: FormatContext, { limit, offset, singleResult }: Query.QueryBase): Statement;
71
+ formatSelection(ctx: FormatContext, selection: ExprData, formatSubject?: FormatSubject): Statement;
72
+ formatExprJson(ctx: FormatContext, expr: ExprData): Statement;
73
+ formatExprValue(ctx: FormatContext, expr: ExprData): Statement;
74
+ retrieveField(expr: ExprData, field: string): ExprData | undefined;
75
+ formatField(ctx: FormatContext, expr: ExprData, field: string): Statement;
76
+ formatString(ctx: FormatContext, input: string): Statement;
77
+ formatInlineValue(ctx: FormatContext, rawValue: any): Statement;
78
+ formatValue(ctx: FormatContext, rawValue: any): Statement;
79
+ formatExpr({ formatAsIn, ...ctx }: FormatContext, expr: ExprData): Statement;
80
+ }
81
+ export {};
@@ -83,8 +83,10 @@ var Formatter = class {
83
83
  query.selection,
84
84
  topLevel ? formatAsResultObject : void 0
85
85
  );
86
- stmt.addLine("FROM").space();
87
- this.formatTarget(ctx, query.from);
86
+ if (query.from) {
87
+ stmt.addLine("FROM").space();
88
+ this.formatTarget(ctx, query.from);
89
+ }
88
90
  this.formatWhere(ctx, query.where);
89
91
  this.formatGroupBy(ctx, query.groupBy);
90
92
  this.formatHaving(ctx, query.having);
@@ -321,8 +323,6 @@ var Formatter = class {
321
323
  throw new TypeError(`Expected boolean for column ${column.name}`);
322
324
  return stmt.raw(this.escapeValue(columnValue));
323
325
  case ColumnType.Json:
324
- if (typeof columnValue !== "object")
325
- throw new TypeError(`Expected object for column ${column.name}`);
326
326
  return stmt.value(JSON.stringify(columnValue));
327
327
  }
328
328
  }
@@ -390,12 +390,15 @@ var Formatter = class {
390
390
  return stmt;
391
391
  }
392
392
  formatLimit(ctx, { limit, offset, singleResult }) {
393
- const { stmt } = ctx;
393
+ const { stmt, forceInline } = ctx;
394
394
  if (!limit && !offset && !singleResult)
395
395
  return stmt;
396
- stmt.newline().raw("LIMIT").addValue(singleResult ? 1 : limit);
397
- if (offset && offset > 0)
398
- stmt.raw("OFFSET").addValue(offset);
396
+ stmt.newline().raw("LIMIT");
397
+ this.formatValue(ctx, singleResult ? 1 : limit);
398
+ if (offset && offset > 0) {
399
+ stmt.raw("OFFSET");
400
+ this.formatValue(ctx, offset);
401
+ }
399
402
  return stmt;
400
403
  }
401
404
  formatSelection(ctx, selection, formatSubject) {
@@ -410,7 +413,7 @@ var Formatter = class {
410
413
  if (formatSubject)
411
414
  formatSubject(stmt, mkSubject);
412
415
  else
413
- mkSubject();
416
+ this.formatExpr(ctx, selection);
414
417
  stmt.add("AS").addIdentifier("result");
415
418
  return stmt;
416
419
  }
@@ -441,7 +444,8 @@ var Formatter = class {
441
444
  case TargetType.Table:
442
445
  const column = expr.target.table.columns[field];
443
446
  const asBoolean = column?.type === ColumnType.Boolean && ctx.formatAsJson;
444
- const asJson = column?.type === ColumnType.Json && ctx.formatAsJson;
447
+ const jsonColumn = column?.type === ColumnType.Json;
448
+ const asJson = jsonColumn && ctx.formatAsJson;
445
449
  if (asJson) {
446
450
  stmt.raw("json");
447
451
  stmt.openParenthesis();
@@ -456,6 +460,8 @@ var Formatter = class {
456
460
  stmt.add(`, 'true', 'false'))`);
457
461
  if (asJson)
458
462
  stmt.closeParenthesis();
463
+ if (jsonColumn && !asJson)
464
+ stmt.raw("->>'$'");
459
465
  return stmt;
460
466
  }
461
467
  default:
@@ -624,7 +630,7 @@ var Formatter = class {
624
630
  stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
625
631
  }
626
632
  stmt.raw("SELECT value AS result").add("FROM json_each").openParenthesis();
627
- this.formatExprJson(ctx, target.expr);
633
+ this.formatExpr(ctx, target.expr);
628
634
  stmt.closeParenthesis();
629
635
  if (target.alias)
630
636
  stmt.add("AS").addIdentifier(target.alias);
@@ -647,7 +653,7 @@ var Formatter = class {
647
653
  stmt.raw("SELECT json_group_array(json(result)) FROM ").openParenthesis();
648
654
  }
649
655
  stmt.raw("SELECT").space();
650
- this.formatExprJson(ctx, result).add("AS result").add("FROM json_each").openParenthesis();
656
+ this.formatExpr(ctx, result).add("AS result").add("FROM json_each").openParenthesis();
651
657
  this.formatExprJson(ctx, target.expr);
652
658
  stmt.closeParenthesis();
653
659
  if (target.alias)
@@ -1,5 +1,5 @@
1
- export interface Sanitizer {
2
- escapeValue(value: any): string;
3
- escapeIdentifier(ident: string): string;
4
- formatParamValue(paramValue: any): any;
5
- }
1
+ export interface Sanitizer {
2
+ escapeValue(value: any): string;
3
+ escapeIdentifier(ident: string): string;
4
+ formatParamValue(paramValue: any): any;
5
+ }
@@ -1,3 +1,3 @@
1
- export declare class SqlError extends Error {
2
- constructor(cause: Error, sql: string);
3
- }
1
+ export declare class SqlError extends Error {
2
+ constructor(cause: Error, sql: string);
3
+ }
@@ -1,33 +1,33 @@
1
- import { ParamData } from '../define/Param';
2
- import { Sanitizer } from './Sanitizer';
3
- export interface StatementOptions {
4
- skipNewlines?: boolean;
5
- }
6
- export declare class Statement {
7
- sanitizer: Sanitizer;
8
- options: StatementOptions;
9
- sql: string;
10
- paramData: Array<ParamData>;
11
- currentIndent: string;
12
- constructor(sanitizer: Sanitizer, options?: StatementOptions);
13
- space(): this;
14
- add(addition: undefined | string): this;
15
- addLine(addition: undefined | string): this;
16
- indent(): this;
17
- dedent(): this;
18
- newline(): this;
19
- identifier(name: string): this;
20
- addIdentifier(name: string): this;
21
- value(value: any): this;
22
- addValue(value: any): this;
23
- param(data: ParamData): this;
24
- addParam(data: ParamData): this;
25
- raw(query: string): this;
26
- openParenthesis(): this;
27
- closeParenthesis(): this;
28
- call<T>(parts: Array<T>, separator?: string): Generator<T, this | undefined, unknown>;
29
- separate<T>(parts: Array<T>, separator?: string): Generator<T, void, unknown>;
30
- isEmpty(): boolean;
31
- params(input?: Record<string, any>): Array<any>;
32
- toString(): string;
33
- }
1
+ import { ParamData } from '../define/Param';
2
+ import { Sanitizer } from './Sanitizer';
3
+ export interface StatementOptions {
4
+ skipNewlines?: boolean;
5
+ }
6
+ export declare class Statement {
7
+ sanitizer: Sanitizer;
8
+ options: StatementOptions;
9
+ sql: string;
10
+ paramData: Array<ParamData>;
11
+ currentIndent: string;
12
+ constructor(sanitizer: Sanitizer, options?: StatementOptions);
13
+ space(): this;
14
+ add(addition: undefined | string): this;
15
+ addLine(addition: undefined | string): this;
16
+ indent(): this;
17
+ dedent(): this;
18
+ newline(): this;
19
+ identifier(name: string): this;
20
+ addIdentifier(name: string): this;
21
+ value(value: any): this;
22
+ addValue(value: any): this;
23
+ param(data: ParamData): this;
24
+ addParam(data: ParamData): this;
25
+ raw(query: string): this;
26
+ openParenthesis(): this;
27
+ closeParenthesis(): this;
28
+ call<T>(parts: Array<T>, separator?: string): Generator<T, this | undefined, unknown>;
29
+ separate<T>(parts: Array<T>, separator?: string): Generator<T, void, unknown>;
30
+ isEmpty(): boolean;
31
+ params(input?: Record<string, any>): Array<any>;
32
+ toString(): string;
33
+ }
@@ -1,11 +1,11 @@
1
- import { ExprData } from '../define/Expr';
2
- import { FormatContext, Formatter } from '../lib/Formatter';
3
- import { Statement } from '../lib/Statement';
4
- export declare class SqliteFormatter extends Formatter {
5
- formatParamValue(paramValue: any): any;
6
- escapeValue(value: any): string;
7
- escapeIdentifier(input: string): string;
8
- escapeString(input: string): string;
9
- formatAccess(ctx: FormatContext, mkSubject: () => void, field: string): Statement;
10
- formatExpr(ctx: FormatContext, expr: ExprData): Statement;
11
- }
1
+ import { ExprData } from '../define/Expr';
2
+ import { FormatContext, Formatter } from '../lib/Formatter';
3
+ import { Statement } from '../lib/Statement';
4
+ export declare class SqliteFormatter extends Formatter {
5
+ formatParamValue(paramValue: any): any;
6
+ escapeValue(value: any): string;
7
+ escapeIdentifier(input: string): string;
8
+ escapeString(input: string): string;
9
+ formatAccess(ctx: FormatContext, mkSubject: () => void, field: string): Statement;
10
+ formatExpr(ctx: FormatContext, expr: ExprData): Statement;
11
+ }