rado 0.1.24 → 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.
@@ -1,16 +1,14 @@
1
1
  import type { Database } from 'better-sqlite3';
2
2
  import { Driver } from '../lib/Driver';
3
3
  import { SchemaInstructions } from '../lib/Schema';
4
- import { Statement } from '../lib/Statement';
4
+ import { CompiledStatement } from '../lib/Statement';
5
+ import { SqliteSchema } from '../sqlite/SqliteSchema';
5
6
  export declare class BetterSqlite3Driver extends Driver.Sync {
6
7
  db: Database;
8
+ tableData: (tableName: string) => Array<SqliteSchema.Column>;
9
+ indexData: (tableName: string) => Array<SqliteSchema.Index>;
7
10
  constructor(db: Database);
8
- rows<T extends object = object>([sql, params]: Statement.Compiled): Array<T>;
9
- values([sql, params]: Statement.Compiled): Array<Array<any>>;
10
- execute([sql, params]: Statement.Compiled): void;
11
- mutate([sql, params]: Statement.Compiled): {
12
- rowsAffected: number;
13
- };
11
+ prepareStatement(stmt: CompiledStatement): Driver.Sync.PreparedStatement;
14
12
  schemaInstructions(tableName: string): SchemaInstructions | undefined;
15
13
  export(): Uint8Array;
16
14
  }
@@ -2,31 +2,38 @@
2
2
  import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
+ var PreparedStatement = class {
6
+ constructor(stmt) {
7
+ this.stmt = stmt;
8
+ }
9
+ all(params = []) {
10
+ return this.stmt.all(...params);
11
+ }
12
+ run(params = []) {
13
+ return { rowsAffected: this.stmt.run(...params).changes };
14
+ }
15
+ get(params = []) {
16
+ return this.stmt.get(...params);
17
+ }
18
+ execute(params = []) {
19
+ this.stmt.run(...params);
20
+ }
21
+ };
5
22
  var BetterSqlite3Driver = class extends Driver.Sync {
6
23
  constructor(db) {
7
24
  super(new SqliteFormatter());
8
25
  this.db = db;
26
+ this.tableData = this.prepare(SqliteSchema.tableData);
27
+ this.indexData = this.prepare(SqliteSchema.indexData);
9
28
  }
10
- rows([sql, params]) {
11
- return this.db.prepare(sql).all(...params);
12
- }
13
- values([sql, params]) {
14
- return this.db.prepare(sql).raw().all(...params);
15
- }
16
- execute([sql, params]) {
17
- this.db.prepare(sql).run(...params);
18
- }
19
- mutate([sql, params]) {
20
- const { changes } = this.db.prepare(sql).run(...params);
21
- return { rowsAffected: changes };
29
+ tableData;
30
+ indexData;
31
+ prepareStatement(stmt) {
32
+ return new PreparedStatement(this.db.prepare(stmt.sql));
22
33
  }
23
34
  schemaInstructions(tableName) {
24
- const columnData = this.rows(
25
- SqliteSchema.tableData(tableName).compile(this.formatter)
26
- );
27
- const indexData = this.rows(
28
- SqliteSchema.indexData(tableName).compile(this.formatter)
29
- );
35
+ const columnData = this.tableData(tableName);
36
+ const indexData = this.indexData(tableName);
30
37
  return SqliteSchema.createInstructions(columnData, indexData);
31
38
  }
32
39
  export() {
@@ -1,16 +1,14 @@
1
1
  import type { Database } from 'sql.js';
2
2
  import { Driver } from '../lib/Driver';
3
3
  import { SchemaInstructions } from '../lib/Schema';
4
- import { Statement } from '../lib/Statement';
4
+ import { CompiledStatement } from '../lib/Statement';
5
+ import { SqliteSchema } from '../sqlite/SqliteSchema';
5
6
  export declare class SqlJsDriver extends Driver.Sync {
6
7
  db: Database;
8
+ tableData: (tableName: string) => Array<SqliteSchema.Column>;
9
+ indexData: (tableName: string) => Array<SqliteSchema.Index>;
7
10
  constructor(db: Database);
8
- rows<T extends object = object>([sql, params]: Statement.Compiled): Array<T>;
9
- values([sql, params]: Statement.Compiled): Array<Array<any>>;
10
- execute([sql, params]: Statement.Compiled): void;
11
- mutate([sql, params]: Statement.Compiled): {
12
- rowsAffected: number;
13
- };
11
+ prepareStatement(stmt: CompiledStatement): Driver.Sync.PreparedStatement;
14
12
  schemaInstructions(tableName: string): SchemaInstructions | undefined;
15
13
  export(): Uint8Array;
16
14
  }
@@ -2,41 +2,44 @@
2
2
  import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
- var SqlJsDriver = class extends Driver.Sync {
6
- constructor(db) {
7
- super(new SqliteFormatter());
5
+ var PreparedStatement = class {
6
+ constructor(db, stmt) {
8
7
  this.db = db;
8
+ this.stmt = stmt;
9
9
  }
10
- rows([sql, params]) {
11
- const stmt = this.db.prepare(sql);
12
- stmt.bind(params);
10
+ all(params) {
11
+ this.stmt.bind(params);
13
12
  const res = [];
14
- while (stmt.step())
15
- res.push(stmt.getAsObject());
13
+ while (this.stmt.step())
14
+ res.push(this.stmt.getAsObject());
16
15
  return res;
17
16
  }
18
- values([sql, params]) {
19
- const stmt = this.db.prepare(sql);
20
- stmt.bind(params);
21
- const res = [];
22
- while (stmt.step())
23
- res.push(stmt.get());
24
- return res;
17
+ run(params) {
18
+ this.stmt.run(params);
19
+ return { rowsAffected: this.db.getRowsModified() };
25
20
  }
26
- execute([sql, params]) {
27
- this.db.prepare(sql).run(params);
21
+ get(params) {
22
+ return this.all(params)[0];
28
23
  }
29
- mutate([sql, params]) {
30
- this.db.prepare(sql).run(params);
31
- return { rowsAffected: this.db.getRowsModified() };
24
+ execute(params) {
25
+ this.stmt.run(params);
26
+ }
27
+ };
28
+ var SqlJsDriver = class extends Driver.Sync {
29
+ constructor(db) {
30
+ super(new SqliteFormatter());
31
+ this.db = db;
32
+ this.tableData = this.prepare(SqliteSchema.tableData);
33
+ this.indexData = this.prepare(SqliteSchema.indexData);
34
+ }
35
+ tableData;
36
+ indexData;
37
+ prepareStatement(stmt) {
38
+ return new PreparedStatement(this.db, this.db.prepare(stmt.sql));
32
39
  }
33
40
  schemaInstructions(tableName) {
34
- const columnData = this.rows(
35
- SqliteSchema.tableData(tableName).compile(this.formatter)
36
- );
37
- const indexData = this.rows(
38
- SqliteSchema.indexData(tableName).compile(this.formatter)
39
- );
41
+ const columnData = this.tableData(tableName);
42
+ const indexData = this.indexData(tableName);
40
43
  return SqliteSchema.createInstructions(columnData, indexData);
41
44
  }
42
45
  export() {
@@ -2,18 +2,16 @@ import type { Database } from 'sqlite3';
2
2
  import { Driver } from '../lib/Driver';
3
3
  import { Query } from '../lib/Query';
4
4
  import { SchemaInstructions } from '../lib/Schema';
5
- import { Statement } from '../lib/Statement';
5
+ import { CompiledStatement } from '../lib/Statement';
6
+ import { SqliteSchema } from '../sqlite/SqliteSchema';
6
7
  export declare class Sqlite3Driver extends Driver.Async {
7
8
  private db;
8
9
  lock: Promise<void> | undefined;
10
+ tableData: (tableName: string) => Promise<Array<SqliteSchema.Column>>;
11
+ indexData: (tableName: string) => Promise<Array<SqliteSchema.Index>>;
9
12
  constructor(db: Database);
10
- executeQuery<T>(query: Query<T>): Promise<T>;
11
- rows<T extends object = object>([sql, params]: Statement.Compiled): Promise<Array<T>>;
12
- values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
13
- execute([sql, params]: Statement.Compiled): Promise<void>;
14
- mutate([sql, params]: Statement.Compiled): Promise<{
15
- rowsAffected: number;
16
- }>;
13
+ executeQuery<T>(query: Query<T>, stmt?: Driver.Async.PreparedStatement, params?: any[] | undefined): Promise<T>;
14
+ prepareStatement(stmt: CompiledStatement): Driver.Async.PreparedStatement;
17
15
  schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
18
16
  isolate(): [connection: Driver.Async, release: () => Promise<void>];
19
17
  }
@@ -2,20 +2,13 @@
2
2
  import { Driver } from "../lib/Driver.js";
3
3
  import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
4
4
  import { SqliteSchema } from "../sqlite/SqliteSchema.js";
5
- var Sqlite3Driver = class extends Driver.Async {
6
- constructor(db) {
7
- super(new SqliteFormatter());
8
- this.db = db;
9
- }
10
- lock;
11
- async executeQuery(query) {
12
- await this.lock;
13
- return super.executeQuery(query);
5
+ var PreparedStatement = class {
6
+ constructor(stmt) {
7
+ this.stmt = stmt;
14
8
  }
15
- rows([sql, params]) {
9
+ all(params) {
16
10
  return new Promise((resolve, reject) => {
17
- const stmt = this.db.prepare(sql);
18
- stmt.all(params, (err, rows) => {
11
+ this.stmt.all(params, (err, rows) => {
19
12
  if (err)
20
13
  reject(err);
21
14
  else
@@ -23,39 +16,57 @@ var Sqlite3Driver = class extends Driver.Async {
23
16
  });
24
17
  });
25
18
  }
26
- async values(stmt) {
27
- const rows = await this.rows(stmt);
28
- return rows.map(Object.values);
19
+ run(params) {
20
+ return new Promise((resolve, reject) => {
21
+ this.stmt.run(params, function(err) {
22
+ if (err)
23
+ reject(err);
24
+ else
25
+ resolve({ rowsAffected: this.changes });
26
+ });
27
+ });
29
28
  }
30
- execute([sql, params]) {
29
+ get(params) {
31
30
  return new Promise((resolve, reject) => {
32
- const stmt = this.db.prepare(sql);
33
- stmt.run(params, (err) => {
31
+ this.stmt.get(params, (err, row) => {
34
32
  if (err)
35
33
  reject(err);
36
34
  else
37
- resolve();
35
+ resolve(row);
38
36
  });
39
37
  });
40
38
  }
41
- mutate([sql, params]) {
39
+ execute(params) {
42
40
  return new Promise((resolve, reject) => {
43
- const stmt = this.db.prepare(sql);
44
- stmt.run(params, function(err) {
41
+ this.stmt.run(params, (err) => {
45
42
  if (err)
46
43
  reject(err);
47
44
  else
48
- resolve({ rowsAffected: this.changes });
45
+ resolve();
49
46
  });
50
47
  });
51
48
  }
49
+ };
50
+ var Sqlite3Driver = class extends Driver.Async {
51
+ constructor(db) {
52
+ super(new SqliteFormatter());
53
+ this.db = db;
54
+ this.tableData = this.prepare(SqliteSchema.tableData);
55
+ this.indexData = this.prepare(SqliteSchema.indexData);
56
+ }
57
+ lock;
58
+ tableData;
59
+ indexData;
60
+ async executeQuery(query, stmt, params) {
61
+ await this.lock;
62
+ return super.executeQuery(query, stmt, params);
63
+ }
64
+ prepareStatement(stmt) {
65
+ return new PreparedStatement(this.db.prepare(stmt.sql));
66
+ }
52
67
  async schemaInstructions(tableName) {
53
- const columnData = await this.rows(
54
- SqliteSchema.tableData(tableName).compile(this.formatter)
55
- );
56
- const indexData = await this.rows(
57
- SqliteSchema.indexData(tableName).compile(this.formatter)
58
- );
68
+ const columnData = await this.tableData(tableName);
69
+ const indexData = await this.indexData(tableName);
59
70
  return SqliteSchema.createInstructions(columnData, indexData);
60
71
  }
61
72
  isolate() {
@@ -8,6 +8,7 @@ import { Update as UpdateSet } from './Update';
8
8
  export declare class Cursor<T> {
9
9
  [Selection.__cursorType](): T;
10
10
  constructor(query: Query<T>);
11
+ static all(strings: TemplateStringsArray, ...params: Array<any>): Cursor<any>;
11
12
  query(): Query<T>;
12
13
  toJSON(): Query<T>;
13
14
  }
@@ -19,7 +20,7 @@ export declare namespace Cursor {
19
20
  class Filterable<T> extends Limitable<T> {
20
21
  where(...where: Array<EV<boolean>>): Filterable<T>;
21
22
  }
22
- class Delete<T> extends Filterable<{
23
+ class Delete extends Filterable<{
23
24
  rowsAffected: number;
24
25
  }> {
25
26
  query(): Query.Delete;
@@ -15,6 +15,9 @@ var Cursor = class {
15
15
  value: () => query
16
16
  });
17
17
  }
18
+ static all(strings, ...params) {
19
+ return new Cursor(Query.Raw({ expectedReturn: "rows", strings, params }));
20
+ }
18
21
  query() {
19
22
  throw new Error("Not implemented");
20
23
  }
@@ -1,8 +1,9 @@
1
1
  import { Cursor } from './Cursor';
2
+ import { Expr } from './Expr';
2
3
  import { Formatter } from './Formatter';
3
4
  import { Query } from './Query';
4
5
  import { SchemaInstructions } from './Schema';
5
- import { Statement } from './Statement';
6
+ import { CompiledStatement } from './Statement';
6
7
  import { Table } from './Table';
7
8
  declare class Callable extends Function {
8
9
  constructor(fn: Function);
@@ -10,12 +11,18 @@ declare class Callable extends Function {
10
11
  declare abstract class DriverBase extends Callable {
11
12
  formatter: Formatter;
12
13
  constructor(formatter: Formatter);
14
+ compile<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): [Query<T>, CompiledStatement];
13
15
  all(...args: Array<any>): any;
14
16
  get(...args: Array<any>): any;
15
17
  sql(strings: TemplateStringsArray, ...params: Array<any>): Cursor<unknown>;
16
18
  executeTemplate(expectedReturn: Query.RawReturn, strings: TemplateStringsArray, ...params: Array<any>): any;
17
19
  abstract executeQuery(query: Query<any>): any;
18
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
+ };
19
26
  interface SyncDriver {
20
27
  <T>(query: Cursor<T>): T;
21
28
  <T>(...queries: Array<Cursor<any>>): T;
@@ -23,17 +30,13 @@ interface SyncDriver {
23
30
  }
24
31
  declare abstract class SyncDriver extends DriverBase {
25
32
  transactionId: number;
26
- abstract rows(stmt: Statement.Compiled): Array<object>;
27
- abstract values(stmt: Statement.Compiled): Array<Array<any>>;
28
- abstract execute(stmt: Statement.Compiled): void;
29
- abstract mutate(stmt: Statement.Compiled): {
30
- rowsAffected: number;
31
- };
33
+ abstract prepareStatement(stmt: CompiledStatement): SyncPreparedStatement;
32
34
  abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
35
+ prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => R;
33
36
  migrateSchema(...tables: Array<Table<any>>): unknown;
34
- executeQuery<T>(query: Query<T>): T;
37
+ executeQuery<T>(query: Query<T>, stmt?: SyncPreparedStatement, params?: Array<any>): T;
35
38
  all<T>(cursor: Cursor.SelectSingle<T>): Array<T>;
36
- all<T>(cursor: Cursor<T>): Array<T>;
39
+ all<T>(cursor: Cursor<T>): T;
37
40
  all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
38
41
  get<T>(cursor: Cursor.SelectMultiple<T>): T | null;
39
42
  get<T>(cursor: Cursor<T>): T;
@@ -41,6 +44,14 @@ declare abstract class SyncDriver extends DriverBase {
41
44
  transaction<T>(run: (query: SyncDriver) => T): T;
42
45
  toAsync(): SyncWrapper;
43
46
  }
47
+ interface SyncPreparedStatement {
48
+ run(params?: Array<any>): {
49
+ rowsAffected: number;
50
+ };
51
+ all<T>(params?: Array<any>): Array<T>;
52
+ get<T>(params?: Array<any>): T;
53
+ execute(params?: Array<any>): void;
54
+ }
44
55
  interface AsyncDriver {
45
56
  <T>(query: Cursor<T>): Promise<T>;
46
57
  <T>(...queries: Array<Cursor<any>>): Promise<T>;
@@ -49,15 +60,11 @@ interface AsyncDriver {
49
60
  declare abstract class AsyncDriver extends DriverBase {
50
61
  transactionId: number;
51
62
  abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
52
- abstract rows(stmt: Statement.Compiled): Promise<Array<object>>;
53
- abstract values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
54
- abstract execute(stmt: Statement.Compiled): Promise<void>;
55
- abstract mutate(stmt: Statement.Compiled): Promise<{
56
- rowsAffected: number;
57
- }>;
63
+ abstract prepareStatement(stmt: CompiledStatement): AsyncPreparedStatement;
58
64
  abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
65
+ prepare<T extends Array<Expr<any>>, R>(create: (...params: T) => Cursor<R>): (...params: ParamTypes<T>) => Promise<R>;
59
66
  migrateSchema(...tables: Array<Table<any>>): Promise<unknown>;
60
- executeQuery<T>(query: Query<T>): Promise<T>;
67
+ executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
61
68
  all<T>(cursor: Cursor.SelectSingle<T>): Promise<Array<T>>;
62
69
  all<T>(cursor: Cursor<T>): Promise<T>;
63
70
  all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
@@ -70,20 +77,29 @@ declare class SyncWrapper extends AsyncDriver {
70
77
  private sync;
71
78
  lock: Promise<void> | undefined;
72
79
  constructor(sync: SyncDriver);
73
- executeQuery<T>(query: Query<T>): Promise<T>;
74
- rows(stmt: Statement.Compiled): Promise<Array<object>>;
75
- values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
76
- execute(stmt: Statement.Compiled): Promise<void>;
77
- mutate(stmt: Statement.Compiled): Promise<{
78
- rowsAffected: number;
79
- }>;
80
+ executeQuery<T>(query: Query<T>, stmt?: AsyncPreparedStatement, params?: Array<any>): Promise<T>;
81
+ prepareStatement(stmt: CompiledStatement): AsyncPreparedStatement;
80
82
  schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
81
83
  isolate(): [connection: AsyncDriver, release: () => Promise<void>];
82
84
  }
85
+ interface AsyncPreparedStatement {
86
+ run(params?: Array<any>): Promise<{
87
+ rowsAffected: number;
88
+ }>;
89
+ all<T>(params?: Array<any>): Promise<Array<T>>;
90
+ get<T>(params?: Array<any>): Promise<T>;
91
+ execute(params?: Array<any>): Promise<void>;
92
+ }
83
93
  export declare namespace Driver {
84
94
  type Sync = SyncDriver;
85
95
  const Sync: typeof SyncDriver;
96
+ namespace Sync {
97
+ type PreparedStatement = SyncPreparedStatement;
98
+ }
86
99
  type Async = AsyncDriver;
87
100
  const Async: typeof AsyncDriver;
101
+ namespace Async {
102
+ type PreparedStatement = AsyncPreparedStatement;
103
+ }
88
104
  }
89
105
  export {};
@@ -1,5 +1,7 @@
1
1
  // src/lib/Driver.ts
2
2
  import { Cursor } from "./Cursor.js";
3
+ import { Expr, ExprData } from "./Expr.js";
4
+ import { ParamData } from "./Param.js";
3
5
  import { Query, QueryType } from "./Query.js";
4
6
  import { Schema } from "./Schema.js";
5
7
  var Callable = class extends Function {
@@ -31,6 +33,16 @@ var DriverBase = class extends Callable {
31
33
  });
32
34
  this.formatter = formatter;
33
35
  }
36
+ compile(create) {
37
+ const { length } = create;
38
+ const paramNames = Array.from({ length }, (_, i) => `p${i}`);
39
+ const params = paramNames.map(
40
+ (name) => new Expr(ExprData.Param(ParamData.Named(name)))
41
+ );
42
+ const cursor = create(...params);
43
+ const query = cursor.query();
44
+ return [query, this.formatter.compile(query)];
45
+ }
34
46
  all(...args) {
35
47
  const [input, ...rest] = args;
36
48
  if (input instanceof Cursor.SelectSingle)
@@ -56,6 +68,16 @@ var DriverBase = class extends Callable {
56
68
  };
57
69
  var SyncDriver = class extends DriverBase {
58
70
  transactionId = 0;
71
+ prepare(create) {
72
+ const [query, compiled] = this.compile(create);
73
+ const prepared = this.prepareStatement(compiled);
74
+ return (...params) => {
75
+ const namedParams = Object.fromEntries(
76
+ params.map((value, i) => [`p${i}`, value])
77
+ );
78
+ return this.executeQuery(query, prepared, compiled.params(namedParams));
79
+ };
80
+ }
59
81
  migrateSchema(...tables) {
60
82
  const queries = [];
61
83
  for (const table of Object.values(tables)) {
@@ -71,7 +93,7 @@ var SyncDriver = class extends DriverBase {
71
93
  }
72
94
  return this.executeQuery(Query.Batch({ queries }));
73
95
  }
74
- executeQuery(query) {
96
+ executeQuery(query, stmt, params) {
75
97
  switch (query.type) {
76
98
  case QueryType.Batch:
77
99
  let result;
@@ -86,24 +108,26 @@ var SyncDriver = class extends DriverBase {
86
108
  return result;
87
109
  });
88
110
  default:
89
- const stmt = this.formatter.compile(query);
111
+ const compiled = stmt ? void 0 : this.formatter.compile(query);
112
+ stmt = stmt || this.prepareStatement(compiled);
113
+ params = params || compiled.params();
90
114
  if ("selection" in query) {
91
- const res = this.values(stmt).map(([item]) => JSON.parse(item).result);
115
+ const res = stmt.all(params).map((row) => JSON.parse(row.result).result);
92
116
  if (query.singleResult)
93
117
  return res[0];
94
118
  return res;
95
119
  } else if (query.type === QueryType.Raw) {
96
120
  switch (query.expectedReturn) {
97
121
  case "row":
98
- return this.rows(stmt)[0];
122
+ return stmt.all(params)[0];
99
123
  case "rows":
100
- return this.rows(stmt);
124
+ return stmt.all(params);
101
125
  default:
102
- this.execute(stmt);
126
+ stmt.execute(params);
103
127
  return void 0;
104
128
  }
105
129
  } else {
106
- return this.mutate(stmt);
130
+ return stmt.run(params);
107
131
  }
108
132
  }
109
133
  }
@@ -137,6 +161,16 @@ var SyncDriver = class extends DriverBase {
137
161
  };
138
162
  var AsyncDriver = class extends DriverBase {
139
163
  transactionId = 0;
164
+ prepare(create) {
165
+ const [query, compiled] = this.compile(create);
166
+ const prepared = this.prepareStatement(compiled);
167
+ return (...params) => {
168
+ const namedParams = Object.fromEntries(
169
+ params.map((value, i) => [`p${i}`, value])
170
+ );
171
+ return this.executeQuery(query, prepared, compiled.params(namedParams));
172
+ };
173
+ }
140
174
  async migrateSchema(...tables) {
141
175
  const queries = [];
142
176
  for (const table of Object.values(tables)) {
@@ -152,7 +186,7 @@ var AsyncDriver = class extends DriverBase {
152
186
  }
153
187
  return this.executeQuery(Query.Batch({ queries }));
154
188
  }
155
- async executeQuery(query) {
189
+ async executeQuery(query, stmt, params) {
156
190
  switch (query.type) {
157
191
  case QueryType.Batch:
158
192
  let result;
@@ -167,10 +201,12 @@ var AsyncDriver = class extends DriverBase {
167
201
  return result;
168
202
  });
169
203
  default:
170
- const stmt = this.formatter.compile(query);
204
+ const compiled = stmt ? void 0 : this.formatter.compile(query);
205
+ stmt = stmt || this.prepareStatement(compiled);
206
+ params = params || compiled.params();
171
207
  if ("selection" in query) {
172
- const res = (await this.values(stmt)).map(
173
- ([item]) => JSON.parse(item).result
208
+ const res = (await stmt.all(params)).map(
209
+ (item) => JSON.parse(item.result).result
174
210
  );
175
211
  if (query.singleResult)
176
212
  return res[0];
@@ -178,15 +214,15 @@ var AsyncDriver = class extends DriverBase {
178
214
  } else if (query.type === QueryType.Raw) {
179
215
  switch (query.expectedReturn) {
180
216
  case "row":
181
- return (await this.rows(stmt))[0];
217
+ return (await stmt.all(params))[0];
182
218
  case "rows":
183
- return await this.rows(stmt);
219
+ return await stmt.all(params);
184
220
  default:
185
- await this.execute(stmt);
221
+ await stmt.execute(params);
186
222
  return void 0;
187
223
  }
188
224
  } else {
189
- return await this.mutate(stmt);
225
+ return await stmt.run(params);
190
226
  }
191
227
  }
192
228
  }
@@ -218,27 +254,35 @@ var AsyncDriver = class extends DriverBase {
218
254
  }
219
255
  }
220
256
  };
257
+ var SyncPreparedStatementWrapper = class {
258
+ constructor(stmt) {
259
+ this.stmt = stmt;
260
+ }
261
+ async run(params) {
262
+ return this.stmt.run(params);
263
+ }
264
+ async all(params) {
265
+ return this.stmt.all(params);
266
+ }
267
+ async get(params) {
268
+ return this.stmt.get(params);
269
+ }
270
+ async execute(params) {
271
+ return this.stmt.execute(params);
272
+ }
273
+ };
221
274
  var SyncWrapper = class extends AsyncDriver {
222
275
  constructor(sync) {
223
276
  super(sync.formatter);
224
277
  this.sync = sync;
225
278
  }
226
279
  lock;
227
- async executeQuery(query) {
280
+ async executeQuery(query, stmt, params) {
228
281
  await this.lock;
229
- return super.executeQuery(query);
230
- }
231
- async rows(stmt) {
232
- return this.sync.rows(stmt);
233
- }
234
- async values(stmt) {
235
- return this.sync.values(stmt);
236
- }
237
- async execute(stmt) {
238
- return this.sync.execute(stmt);
282
+ return super.executeQuery(query, stmt, params);
239
283
  }
240
- async mutate(stmt) {
241
- return this.sync.mutate(stmt);
284
+ prepareStatement(stmt) {
285
+ return new SyncPreparedStatementWrapper(this.sync.prepareStatement(stmt));
242
286
  }
243
287
  async schemaInstructions(tableName) {
244
288
  return this.sync.schemaInstructions(tableName);
@@ -19,7 +19,7 @@ export declare abstract class Formatter implements Sanitizer {
19
19
  abstract formatSqlAccess(on: Statement, field: string): Statement;
20
20
  abstract formatJsonAccess(on: Statement, field: string): Statement;
21
21
  formatAccess(on: Statement, field: string, formatAsJson?: boolean): Statement;
22
- compile<T>(query: Query<T>, formatInline?: boolean): Statement.Compiled;
22
+ compile<T>(query: Query<T>, formatInline?: boolean): import("./Statement").CompiledStatement;
23
23
  format<T>(query: Query<T>, ctx?: FormatContext): Statement;
24
24
  formatSelect(query: Query.Select, ctx: FormatContext): Statement;
25
25
  formatInsert(query: Query.Insert, ctx: FormatContext): Statement;
@@ -1,6 +1,6 @@
1
1
  // src/lib/Formatter.ts
2
2
  import { ColumnType } from "./Column.js";
3
- import { BinOp, ExprData, ExprType, UnOp } from "./Expr.js";
3
+ import { BinOp, Expr, ExprData, ExprType, UnOp } from "./Expr.js";
4
4
  import { OrderDirection } from "./OrderBy.js";
5
5
  import { ParamType } from "./Param.js";
6
6
  import { Query, QueryType } from "./Query.js";
@@ -9,6 +9,7 @@ import {
9
9
  call,
10
10
  identifier,
11
11
  newline,
12
+ param,
12
13
  parenthesis,
13
14
  raw,
14
15
  separated,
@@ -163,7 +164,14 @@ var Formatter = class {
163
164
  );
164
165
  }
165
166
  formatRaw({ strings, params }, ctx) {
166
- return Statement.tag(strings, ...params);
167
+ return Statement.tag(
168
+ strings,
169
+ params.map((param2) => {
170
+ if (param2 instanceof Expr)
171
+ return this.formatExpr(param2.expr, ctx);
172
+ return this.formatValue(param2, ctx);
173
+ })
174
+ );
167
175
  }
168
176
  formatColumn(column) {
169
177
  return identifier(column.name).add(this.formatType(column.type)).addIf(column.unique, "UNIQUE").addIf(column.autoIncrement, "AUTOINCREMENT").addIf(column.primaryKey, "PRIMARY KEY").addIf(!column.nullable, "NOT NULL").addIf(
@@ -209,6 +217,8 @@ var Formatter = class {
209
217
  );
210
218
  }
211
219
  formatColumnValue(column, columnValue) {
220
+ if (columnValue instanceof Expr)
221
+ return this.formatExprValue(columnValue.expr, {});
212
222
  const isNull = columnValue === void 0 || columnValue === null;
213
223
  const isOptional = column.nullable || column.autoIncrement || column.primaryKey;
214
224
  if (isNull) {
@@ -231,7 +241,7 @@ var Formatter = class {
231
241
  case ColumnType.Boolean:
232
242
  if (typeof columnValue !== "boolean")
233
243
  throw new TypeError(`Expected boolean for column ${column.name}`);
234
- return value(columnValue);
244
+ return raw(this.escapeValue(columnValue));
235
245
  case ColumnType.Json:
236
246
  if (typeof columnValue !== "object")
237
247
  throw new TypeError(`Expected object for column ${column.name}`);
@@ -409,7 +419,7 @@ var Formatter = class {
409
419
  case ParamType.Value:
410
420
  return this.formatValue(expr.param.value, ctx);
411
421
  case ParamType.Named:
412
- throw new Error("todo");
422
+ return param(expr.param.name);
413
423
  }
414
424
  case ExprType.Field:
415
425
  return this.formatField(expr.expr, expr.field, ctx);
@@ -1,8 +1,8 @@
1
1
  import { Expr, ExprData } from './Expr';
2
2
  interface PartialIndexData {
3
3
  on: Array<ExprData>;
4
- where?: ExprData;
5
4
  unique?: boolean;
5
+ where?: ExprData;
6
6
  }
7
7
  export interface IndexData extends PartialIndexData {
8
8
  name: string;
@@ -10,8 +10,8 @@ export interface IndexData extends PartialIndexData {
10
10
  export declare class Index {
11
11
  data: PartialIndexData;
12
12
  constructor(data: PartialIndexData);
13
- where(where: Expr<boolean>): Index;
14
13
  unique(): Index;
14
+ where(where: Expr<boolean>): Index;
15
15
  }
16
16
  export declare function index(...on: Array<Expr<any>>): Index;
17
17
  export {};
package/dist/lib/Index.js CHANGED
@@ -4,12 +4,12 @@ var Index = class {
4
4
  constructor(data) {
5
5
  this.data = data;
6
6
  }
7
- where(where) {
8
- return new Index({ ...this.data, where: ExprData.create(where) });
9
- }
10
7
  unique() {
11
8
  return new Index({ ...this.data, unique: true });
12
9
  }
10
+ where(where) {
11
+ return new Index({ ...this.data, where: ExprData.create(where) });
12
+ }
13
13
  };
14
14
  function index(...on) {
15
15
  return new Index({ on: on.map(ExprData.create) });
package/dist/lib/Ops.d.ts CHANGED
@@ -4,5 +4,5 @@ export declare function selectAll<Row>(table: Table<Row>): Cursor.SelectMultiple
4
4
  export declare function selectFirst<Row>(table: Table<Row>): Cursor.SelectSingle<Row>;
5
5
  export declare function update<Row>(table: Table<Row>): Cursor.Update<Row>;
6
6
  export declare function insertInto<Row>(table: Table<Row>): Cursor.Insert<Row>;
7
- export declare function deleteFrom<Row>(table: Table<Row>): Cursor.Delete<Row>;
7
+ export declare function deleteFrom<Row>(table: Table<Row>): Cursor.Delete;
8
8
  export declare function create(...tables: Array<Table<any>>): Cursor.Batch;
@@ -1,3 +1,4 @@
1
+ import { Expr } from './Expr';
1
2
  export declare enum ParamType {
2
3
  Value = "Value",
3
4
  Named = "Named"
@@ -13,3 +14,7 @@ export declare const ParamData: {
13
14
  Value(value: any): ParamData;
14
15
  Named(name: string): ParamData;
15
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
  };
@@ -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
  }
@@ -45,7 +45,7 @@ var Schema;
45
45
  } else if (!schemaIndex) {
46
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)) {
@@ -1,8 +1,10 @@
1
+ import { ParamData } from './Param';
1
2
  import { Sanitizer } from './Sanitizer';
2
3
  declare enum TokenType {
3
4
  Raw = "Raw",
4
5
  Identifier = "Identifier",
5
6
  Value = "Value",
7
+ Param = "Param",
6
8
  Indent = "Indent",
7
9
  Dedent = "Dedent"
8
10
  }
@@ -15,6 +17,7 @@ declare class Token {
15
17
  static Dedent(): Token;
16
18
  static Identifier(data: string): Token;
17
19
  static Value(data: any): Token;
20
+ static Param(name: string): Token;
18
21
  }
19
22
  export interface CompileOptions {
20
23
  formatInline?: boolean;
@@ -25,7 +28,7 @@ export declare class Statement {
25
28
  constructor(tokens: Array<Token>);
26
29
  concat(...tokens: Array<Token | Statement>): Statement;
27
30
  static create(from: string | Statement): Statement;
28
- static tag(strings: ReadonlyArray<string>, ...params: Array<any>): Statement;
31
+ static tag(strings: ReadonlyArray<string>, params: Array<Statement>): Statement;
29
32
  space(): Statement;
30
33
  call(method: string, ...args: Array<Statement>): Statement;
31
34
  addCall(method: string, ...args: Array<Statement>): Statement;
@@ -39,21 +42,28 @@ export declare class Statement {
39
42
  addIdentifier(name: string): Statement;
40
43
  value(value: any): Statement;
41
44
  addValue(value: any): Statement;
45
+ param(name: string): Statement;
46
+ addParam(name: string): Statement;
42
47
  raw(query: string): Statement;
43
48
  parenthesis(inner: string | Statement): Statement;
44
49
  addParenthesis(stmnt: string | Statement): Statement;
45
50
  separated(input: Array<Statement>, separator?: string): Statement;
46
51
  addSeparated(input: Array<Statement>, separator?: string): Statement;
47
52
  isEmpty(): boolean;
48
- compile(sanitizer: Sanitizer, formatInline?: boolean): Statement.Compiled;
53
+ compile(sanitizer: Sanitizer, formatInline?: boolean): CompiledStatement;
49
54
  }
50
- export declare namespace Statement {
51
- type Compiled = [sql: string, params: Array<any>];
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;
52
61
  }
53
62
  export declare function newline(): Statement;
54
63
  export declare function raw(raw: string): Statement;
55
64
  export declare function identifier(name: string): Statement;
56
65
  export declare function value(value: any): Statement;
66
+ export declare function param(name: string): Statement;
57
67
  export declare function empty(): Statement;
58
68
  export declare function parenthesis(stmnt: Statement): Statement;
59
69
  export declare function call(method: string, ...args: Array<Statement>): Statement;
@@ -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,
@@ -1,6 +1,6 @@
1
1
  import { Column, PrimaryKey } from './Column';
2
2
  import { Cursor } from './Cursor';
3
- import { Expr } from './Expr';
3
+ import { EV, Expr } from './Expr';
4
4
  import { Fields } from './Fields';
5
5
  import { Index } from './Index';
6
6
  import { Schema } from './Schema';
@@ -12,6 +12,7 @@ export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>>
12
12
  insertOne(record: Table.Insert<T>): Cursor.Batch<Table.Normalize<T>>;
13
13
  insertAll(data: Array<Table.Insert<T>>): Cursor.InsertValues;
14
14
  set(data: Update<Table.Normalize<T>>): Cursor.Update<Table.Normalize<T>>;
15
+ delete(): Cursor.Delete;
15
16
  createTable(): Cursor.Create;
16
17
  as(alias: string): this;
17
18
  alias(): Record<string, this>;
@@ -21,7 +22,7 @@ export declare class Table<T> extends Cursor.SelectMultiple<Table.Normalize<T>>
21
22
  }
22
23
  export declare namespace Table {
23
24
  type Intersection<A, B> = A & B extends infer U ? {
24
- [P in keyof U]: U[P];
25
+ [P in keyof U]: EV<U[P]>;
25
26
  } : never;
26
27
  type OptionalKeys<T> = {
27
28
  [K in keyof T]: null extends T[K] ? K : T[K] extends Column.IsPrimary<any, any> ? K : T[K] extends Column.IsOptional<any> ? K : never;
@@ -39,15 +40,15 @@ export declare namespace Table {
39
40
  export type Infer<T> = T extends Table<infer U> ? Normalize<U> : never;
40
41
  export {};
41
42
  }
42
- export interface TableOptions<T> {
43
+ export type TableOptions<T, R> = {
43
44
  name: string;
44
45
  alias?: string;
45
46
  columns: {
46
47
  [K in keyof T]: Column<T[K]>;
47
48
  };
48
49
  indexes?: (this: Fields<T>) => Record<string, Index>;
49
- }
50
- export declare function table<T extends {}>(options: TableOptions<T>): Table<T> & Fields<T>;
50
+ };
51
+ export declare function table<T extends {}, R>(options: TableOptions<T, R>): Table<T> & Fields<T>;
51
52
  export declare namespace table {
52
53
  export type infer<T> = Table.Infer<T>;
53
54
  type Extensions<T> = {
package/dist/lib/Table.js CHANGED
@@ -52,6 +52,9 @@ var Table = class extends Cursor.SelectMultiple {
52
52
  })
53
53
  ).set(data);
54
54
  }
55
+ delete() {
56
+ return new Cursor.Delete(Query.Delete({ table: this.schema() }));
57
+ }
55
58
  createTable() {
56
59
  return new Cursor.Create(this.schema());
57
60
  }
@@ -98,13 +101,7 @@ function table(options) {
98
101
  ) : {}
99
102
  ).map(([key, index]) => {
100
103
  const indexName = `${schema.name}.${key}`;
101
- return [
102
- indexName,
103
- {
104
- name: indexName,
105
- ...index.data
106
- }
107
- ];
104
+ return [indexName, { name: indexName, ...index.data }];
108
105
  })
109
106
  );
110
107
  return new Table({
@@ -1,5 +1,6 @@
1
+ import { Cursor } from '../lib/Cursor';
2
+ import { Expr } from '../lib/Expr';
1
3
  import { SchemaInstructions } from '../lib/Schema';
2
- import { Statement } from '../lib/Statement';
3
4
  export declare namespace SqliteSchema {
4
5
  type Column = {
5
6
  cid: number;
@@ -16,8 +17,8 @@ export declare namespace SqliteSchema {
16
17
  rootpage: number;
17
18
  sql: string;
18
19
  }
19
- function tableData(tableName: string): Statement;
20
- function indexData(tableName: string): Statement;
20
+ function tableData(tableName: Expr<string>): Cursor<Array<SqliteSchema.Column>>;
21
+ function indexData(tableName: Expr<string>): Cursor<Array<SqliteSchema.Index>>;
21
22
  function createInstructions(columnData: Array<Column>, indexData: Array<Index>): SchemaInstructions | undefined;
22
23
  function columnInstruction(column: Column): [string, string];
23
24
  function indexInstruction(index: Index): [string, string];
@@ -1,15 +1,16 @@
1
1
  // src/sqlite/SqliteSchema.ts
2
- import { Statement, identifier, raw } from "../lib/Statement.js";
2
+ import { Cursor } from "../lib/Cursor.js";
3
+ import { identifier, raw } from "../lib/Statement.js";
3
4
  import { SqliteFormatter } from "./SqliteFormatter.js";
4
5
  var SqliteSchema;
5
6
  ((SqliteSchema2) => {
6
7
  const formatter = new SqliteFormatter();
7
8
  function tableData(tableName) {
8
- return Statement.tag`select * from pragma_table_info(${tableName}) order by cid`;
9
+ return Cursor.all`select * from pragma_table_info(${tableName}) order by cid`;
9
10
  }
10
11
  SqliteSchema2.tableData = tableData;
11
12
  function indexData(tableName) {
12
- return Statement.tag`select * from sqlite_master where type='index' and tbl_name=${tableName}`;
13
+ return Cursor.all`select * from sqlite_master where type='index' and tbl_name=${tableName}`;
13
14
  }
14
15
  SqliteSchema2.indexData = indexData;
15
16
  function createInstructions(columnData, indexData2) {
@@ -29,7 +30,7 @@ var SqliteSchema;
29
30
  identifier(column.name).add(column.type).addIf(column.pk === 1, "PRIMARY KEY").addIf(column.notnull === 1, "NOT NULL").addIf(
30
31
  column.dflt_value !== null,
31
32
  raw("DEFAULT").addParenthesis(column.dflt_value)
32
- ).compile(formatter)[0]
33
+ ).compile(formatter).sql
33
34
  ];
34
35
  }
35
36
  SqliteSchema2.columnInstruction = columnInstruction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {