rado 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Driver.d.ts CHANGED
@@ -10,66 +10,78 @@ declare class Callable extends Function {
10
10
  declare abstract class DriverBase extends Callable {
11
11
  formatter: Formatter;
12
12
  constructor(formatter: Formatter);
13
- all(strings: TemplateStringsArray, ...params: Array<any>): any;
14
- get(strings: TemplateStringsArray, ...params: Array<any>): any;
13
+ all(...args: Array<any>): any;
14
+ get(...args: Array<any>): any;
15
+ sql(strings: TemplateStringsArray, ...params: Array<any>): Cursor<unknown>;
15
16
  executeTemplate(expectedReturn: Query.RawReturn, strings: TemplateStringsArray, ...params: Array<any>): any;
16
17
  abstract executeQuery(query: Query<any>): any;
17
18
  }
19
+ interface SyncDriver {
20
+ <T>(query: Cursor<T>): T;
21
+ <T>(...queries: Array<Cursor<any>>): T;
22
+ (strings: TemplateStringsArray, ...values: any[]): any;
23
+ }
24
+ declare abstract class SyncDriver extends DriverBase {
25
+ 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
+ };
32
+ abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
33
+ migrateSchema(...tables: Array<Table<any>>): unknown;
34
+ executeQuery<T>(query: Query<T>): T;
35
+ all<T>(cursor: Cursor<T>): Array<T>;
36
+ all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
37
+ get<T>(cursor: Cursor.SelectMultiple<T>): T | null;
38
+ get<T>(cursor: Cursor<T>): T;
39
+ get<T>(strings: TemplateStringsArray, ...params: Array<any>): T;
40
+ transaction<T>(run: (query: SyncDriver) => T): T;
41
+ toAsync(): SyncWrapper;
42
+ }
43
+ interface AsyncDriver {
44
+ <T>(query: Cursor<T>): Promise<T>;
45
+ <T>(...queries: Array<Cursor<any>>): T;
46
+ (strings: TemplateStringsArray, ...values: any[]): Promise<any>;
47
+ }
48
+ declare abstract class AsyncDriver extends DriverBase {
49
+ transactionId: number;
50
+ abstract isolate(): [connection: AsyncDriver, release: () => Promise<void>];
51
+ abstract rows(stmt: Statement.Compiled): Promise<Array<object>>;
52
+ abstract values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
53
+ abstract execute(stmt: Statement.Compiled): Promise<void>;
54
+ abstract mutate(stmt: Statement.Compiled): Promise<{
55
+ rowsAffected: number;
56
+ }>;
57
+ abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
58
+ migrateSchema(...tables: Array<Table<any>>): Promise<unknown>;
59
+ executeQuery<T>(query: Query<T>): Promise<T>;
60
+ all<T>(cursor: Cursor<T>): Promise<Array<T>>;
61
+ all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
62
+ get<T>(cursor: Cursor.SelectMultiple<T>): Promise<T | null>;
63
+ get<T>(cursor: Cursor<T>): Promise<T>;
64
+ get<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<T>;
65
+ transaction<T>(run: (query: AsyncDriver) => T): Promise<T>;
66
+ }
67
+ declare class SyncWrapper extends AsyncDriver {
68
+ private sync;
69
+ lock: Promise<void> | undefined;
70
+ constructor(sync: SyncDriver);
71
+ executeQuery<T>(query: Query<T>): Promise<T>;
72
+ rows(stmt: Statement.Compiled): Promise<Array<object>>;
73
+ values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
74
+ execute(stmt: Statement.Compiled): Promise<void>;
75
+ mutate(stmt: Statement.Compiled): Promise<{
76
+ rowsAffected: number;
77
+ }>;
78
+ schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
79
+ isolate(): [connection: AsyncDriver, release: () => Promise<void>];
80
+ }
18
81
  export declare namespace Driver {
19
- export interface Sync {
20
- <T>(query: Cursor<T>): T;
21
- (strings: TemplateStringsArray, ...values: any[]): any;
22
- }
23
- export abstract class Sync extends DriverBase {
24
- transactionId: number;
25
- abstract rows(stmt: Statement.Compiled): Array<object>;
26
- abstract values(stmt: Statement.Compiled): Array<Array<any>>;
27
- abstract execute(stmt: Statement.Compiled): void;
28
- abstract mutate(stmt: Statement.Compiled): {
29
- rowsAffected: number;
30
- };
31
- abstract schemaInstructions(tableName: string): SchemaInstructions | undefined;
32
- migrateSchema(...tables: Array<Table<any>>): unknown;
33
- executeQuery<T>(query: Query<T>): T;
34
- all<T>(strings: TemplateStringsArray, ...params: Array<any>): Array<T>;
35
- get<T>(strings: TemplateStringsArray, ...params: Array<any>): T;
36
- transaction<T>(run: (query: Sync) => T): T;
37
- toAsync(): SyncWrapper;
38
- }
39
- export interface Async {
40
- <T>(query: Cursor<T>): Promise<T>;
41
- (strings: TemplateStringsArray, ...values: any[]): Promise<any>;
42
- }
43
- export abstract class Async extends DriverBase {
44
- transactionId: number;
45
- abstract isolate(): [connection: Async, release: () => Promise<void>];
46
- abstract rows(stmt: Statement.Compiled): Promise<Array<object>>;
47
- abstract values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
48
- abstract execute(stmt: Statement.Compiled): Promise<void>;
49
- abstract mutate(stmt: Statement.Compiled): Promise<{
50
- rowsAffected: number;
51
- }>;
52
- abstract schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
53
- migrateSchema(...tables: Array<Table<any>>): Promise<unknown>;
54
- executeQuery<T>(query: Query<T>): Promise<T>;
55
- all<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<Array<T>>;
56
- get<T>(strings: TemplateStringsArray, ...params: Array<any>): Promise<T>;
57
- transaction<T>(run: (query: Async) => T): Promise<T>;
58
- }
59
- class SyncWrapper extends Async {
60
- private sync;
61
- lock: Promise<void> | undefined;
62
- constructor(sync: Sync);
63
- executeQuery<T>(query: Query<T>): Promise<T>;
64
- rows(stmt: Statement.Compiled): Promise<Array<object>>;
65
- values(stmt: Statement.Compiled): Promise<Array<Array<any>>>;
66
- execute(stmt: Statement.Compiled): Promise<void>;
67
- mutate(stmt: Statement.Compiled): Promise<{
68
- rowsAffected: number;
69
- }>;
70
- schemaInstructions(tableName: string): Promise<SchemaInstructions | undefined>;
71
- isolate(): [connection: Async, release: () => Promise<void>];
72
- }
73
- export {};
82
+ type Sync = SyncDriver;
83
+ const Sync: typeof SyncDriver;
84
+ type Async = AsyncDriver;
85
+ const Async: typeof AsyncDriver;
74
86
  }
75
87
  export {};
package/dist/Driver.js CHANGED
@@ -12,232 +12,248 @@ var Callable = class extends Function {
12
12
  });
13
13
  }
14
14
  };
15
+ function isTemplateStringsArray(input) {
16
+ return Boolean(Array.isArray(input) && input.raw);
17
+ }
15
18
  var DriverBase = class extends Callable {
16
19
  constructor(formatter) {
17
20
  super((...args) => {
18
21
  const [input, ...rest] = args;
19
- if (input instanceof Cursor)
22
+ if (input instanceof Cursor && rest.length === 0)
20
23
  return this.executeQuery(input.query());
21
- return this.executeTemplate(void 0, input, ...rest);
24
+ if (isTemplateStringsArray(input))
25
+ return this.executeTemplate(void 0, input, ...rest);
26
+ return this.executeQuery(
27
+ Query.Batch({
28
+ queries: args.filter((arg) => arg instanceof Cursor).map((arg) => arg.query())
29
+ })
30
+ );
22
31
  });
23
32
  this.formatter = formatter;
24
33
  }
25
- all(strings, ...params) {
26
- return this.executeTemplate("rows", strings, ...params);
34
+ all(...args) {
35
+ const [input, ...rest] = args;
36
+ if (input instanceof Cursor)
37
+ return this.executeQuery(input.query());
38
+ return this.executeTemplate("rows", input, ...rest);
39
+ }
40
+ get(...args) {
41
+ const [input, ...rest] = args;
42
+ if (input instanceof Cursor.SelectMultiple)
43
+ return this.executeQuery(input.first().query());
44
+ if (input instanceof Cursor)
45
+ return this.executeQuery(input.query());
46
+ return this.executeTemplate("row", input, ...rest);
27
47
  }
28
- get(strings, ...params) {
29
- return this.executeTemplate("row", strings, ...params);
48
+ sql(strings, ...params) {
49
+ return new Cursor(Query.Raw({ strings, params }));
30
50
  }
31
51
  executeTemplate(expectedReturn, strings, ...params) {
32
- if (strings.some((chunk) => chunk.includes("?")))
33
- throw new TypeError("SQL injection hazard");
34
52
  return this.executeQuery(Query.Raw({ strings, params, expectedReturn }));
35
53
  }
36
54
  };
37
- var Driver;
38
- ((Driver2) => {
39
- class Sync extends DriverBase {
40
- transactionId = 0;
41
- migrateSchema(...tables) {
42
- const queries = [];
43
- for (const table of Object.values(tables)) {
44
- const schema = table.schema();
45
- const localSchema = this.schemaInstructions(schema.name);
46
- if (!localSchema) {
47
- queries.push(...Schema.create(schema).queries);
48
- } else {
49
- const changes = Schema.upgrade(this.formatter, localSchema, schema);
50
- if (changes.length)
51
- queries.push(...changes);
52
- }
55
+ var SyncDriver = class extends DriverBase {
56
+ transactionId = 0;
57
+ migrateSchema(...tables) {
58
+ const queries = [];
59
+ for (const table of Object.values(tables)) {
60
+ const schema = table.schema();
61
+ const localSchema = this.schemaInstructions(schema.name);
62
+ if (!localSchema) {
63
+ queries.push(...Schema.create(schema).queries);
64
+ } else {
65
+ const changes = Schema.upgrade(this.formatter, localSchema, schema);
66
+ if (changes.length)
67
+ queries.push(...changes);
53
68
  }
54
- return this.executeQuery(Query.Batch({ queries }));
55
69
  }
56
- executeQuery(query) {
57
- switch (query.type) {
58
- case QueryType.Batch:
59
- let result;
60
- const stmts = query.queries;
61
- if (stmts.length === 0)
62
- return void 0;
63
- if (stmts.length === 1)
64
- return this.executeQuery(stmts[0]);
65
- return this.transaction((cnx) => {
66
- for (const query2 of stmts)
67
- result = cnx.executeQuery(query2);
68
- return result;
69
- });
70
- default:
71
- const stmt = this.formatter.compile(query);
72
- if ("selection" in query) {
73
- const res = this.values(stmt).map(
74
- ([item]) => JSON.parse(item).result
75
- );
76
- if (query.singleResult)
77
- return res[0];
78
- return res;
79
- } else if (query.type === QueryType.Raw) {
80
- switch (query.expectedReturn) {
81
- case "row":
82
- return this.rows(stmt)[0];
83
- case "rows":
84
- return this.rows(stmt);
85
- default:
86
- this.execute(stmt);
87
- return void 0;
88
- }
89
- } else {
90
- return this.mutate(stmt);
70
+ return this.executeQuery(Query.Batch({ queries }));
71
+ }
72
+ executeQuery(query) {
73
+ switch (query.type) {
74
+ case QueryType.Batch:
75
+ let result;
76
+ const stmts = query.queries;
77
+ if (stmts.length === 0)
78
+ return void 0;
79
+ if (stmts.length === 1)
80
+ return this.executeQuery(stmts[0]);
81
+ return this.transaction((cnx) => {
82
+ for (const query2 of stmts)
83
+ result = cnx.executeQuery(query2);
84
+ return result;
85
+ });
86
+ default:
87
+ const stmt = this.formatter.compile(query);
88
+ if ("selection" in query) {
89
+ const res = this.values(stmt).map(([item]) => JSON.parse(item).result);
90
+ if (query.singleResult)
91
+ return res[0];
92
+ return res;
93
+ } else if (query.type === QueryType.Raw) {
94
+ switch (query.expectedReturn) {
95
+ case "row":
96
+ return this.rows(stmt)[0];
97
+ case "rows":
98
+ return this.rows(stmt);
99
+ default:
100
+ this.execute(stmt);
101
+ return void 0;
91
102
  }
92
- }
93
- }
94
- all(strings, ...params) {
95
- return super.all(strings, ...params);
96
- }
97
- get(strings, ...params) {
98
- return super.get(strings, ...params);
103
+ } else {
104
+ return this.mutate(stmt);
105
+ }
99
106
  }
100
- transaction(run) {
101
- const id = `t${this.transactionId++}`;
107
+ }
108
+ all(...args) {
109
+ return super.all(...args);
110
+ }
111
+ get(...args) {
112
+ return super.get(...args);
113
+ }
114
+ transaction(run) {
115
+ const id = `t${this.transactionId++}`;
116
+ this.executeQuery(
117
+ Query.Transaction({ op: Query.TransactionOperation.Begin, id })
118
+ );
119
+ try {
120
+ const res = run(this);
102
121
  this.executeQuery(
103
- Query.Transaction({ op: Query.TransactionOperation.Begin, id })
122
+ Query.Transaction({ op: Query.TransactionOperation.Commit, id })
104
123
  );
105
- try {
106
- const res = run(this);
107
- this.executeQuery(
108
- Query.Transaction({ op: Query.TransactionOperation.Commit, id })
109
- );
110
- return res;
111
- } catch (e) {
112
- this.executeQuery(
113
- Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
114
- );
115
- throw e;
116
- }
117
- }
118
- toAsync() {
119
- return new SyncWrapper(this);
124
+ return res;
125
+ } catch (e) {
126
+ this.executeQuery(
127
+ Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
128
+ );
129
+ throw e;
120
130
  }
121
131
  }
122
- Driver2.Sync = Sync;
123
- class Async extends DriverBase {
124
- transactionId = 0;
125
- async migrateSchema(...tables) {
126
- const queries = [];
127
- for (const table of Object.values(tables)) {
128
- const schema = table.schema();
129
- const localSchema = await this.schemaInstructions(schema.name);
130
- if (!localSchema) {
131
- queries.push(...Schema.create(schema).queries);
132
- } else {
133
- const changes = Schema.upgrade(this.formatter, localSchema, schema);
134
- if (changes.length)
135
- queries.push(...changes);
136
- }
132
+ toAsync() {
133
+ return new SyncWrapper(this);
134
+ }
135
+ };
136
+ var AsyncDriver = class extends DriverBase {
137
+ transactionId = 0;
138
+ async migrateSchema(...tables) {
139
+ const queries = [];
140
+ for (const table of Object.values(tables)) {
141
+ const schema = table.schema();
142
+ const localSchema = await this.schemaInstructions(schema.name);
143
+ if (!localSchema) {
144
+ queries.push(...Schema.create(schema).queries);
145
+ } else {
146
+ const changes = Schema.upgrade(this.formatter, localSchema, schema);
147
+ if (changes.length)
148
+ queries.push(...changes);
137
149
  }
138
- return this.executeQuery(Query.Batch({ queries }));
139
150
  }
140
- async executeQuery(query) {
141
- switch (query.type) {
142
- case QueryType.Batch:
143
- let result;
144
- const stmts = query.queries;
145
- if (stmts.length === 0)
146
- return void 0;
147
- if (stmts.length === 1)
148
- return this.executeQuery(stmts[0]);
149
- return this.transaction(async (cnx) => {
150
- for (const query2 of stmts)
151
- result = await cnx.executeQuery(query2);
152
- return result;
153
- });
154
- default:
155
- const stmt = this.formatter.compile(query);
156
- if ("selection" in query) {
157
- const res = (await this.values(stmt)).map(
158
- ([item]) => JSON.parse(item).result
159
- );
160
- if (query.singleResult)
161
- return res[0];
162
- return res;
163
- } else if (query.type === QueryType.Raw) {
164
- switch (query.expectedReturn) {
165
- case "row":
166
- return (await this.rows(stmt))[0];
167
- case "rows":
168
- return await this.rows(stmt);
169
- default:
170
- await this.execute(stmt);
171
- return void 0;
172
- }
173
- } else {
174
- return await this.mutate(stmt);
151
+ return this.executeQuery(Query.Batch({ queries }));
152
+ }
153
+ async executeQuery(query) {
154
+ switch (query.type) {
155
+ case QueryType.Batch:
156
+ let result;
157
+ const stmts = query.queries;
158
+ if (stmts.length === 0)
159
+ return void 0;
160
+ if (stmts.length === 1)
161
+ return this.executeQuery(stmts[0]);
162
+ return this.transaction(async (cnx) => {
163
+ for (const query2 of stmts)
164
+ result = await cnx.executeQuery(query2);
165
+ return result;
166
+ });
167
+ default:
168
+ const stmt = this.formatter.compile(query);
169
+ if ("selection" in query) {
170
+ const res = (await this.values(stmt)).map(
171
+ ([item]) => JSON.parse(item).result
172
+ );
173
+ if (query.singleResult)
174
+ return res[0];
175
+ return res;
176
+ } else if (query.type === QueryType.Raw) {
177
+ switch (query.expectedReturn) {
178
+ case "row":
179
+ return (await this.rows(stmt))[0];
180
+ case "rows":
181
+ return await this.rows(stmt);
182
+ default:
183
+ await this.execute(stmt);
184
+ return void 0;
175
185
  }
176
- }
177
- }
178
- all(strings, ...params) {
179
- return super.all(strings, ...params);
180
- }
181
- get(strings, ...params) {
182
- return super.get(strings, ...params);
186
+ } else {
187
+ return await this.mutate(stmt);
188
+ }
183
189
  }
184
- async transaction(run) {
185
- const id = `t${this.transactionId++}`;
186
- const [connection, release] = this.isolate();
190
+ }
191
+ all(...args) {
192
+ return super.all(...args);
193
+ }
194
+ get(...args) {
195
+ return super.get(...args);
196
+ }
197
+ async transaction(run) {
198
+ const id = `t${this.transactionId++}`;
199
+ const [connection, release] = this.isolate();
200
+ await connection.executeQuery(
201
+ Query.Transaction({ op: Query.TransactionOperation.Begin, id })
202
+ );
203
+ try {
204
+ const res = await run(connection);
187
205
  await connection.executeQuery(
188
- Query.Transaction({ op: Query.TransactionOperation.Begin, id })
206
+ Query.Transaction({ op: Query.TransactionOperation.Commit, id })
189
207
  );
190
- try {
191
- const res = await run(connection);
192
- await connection.executeQuery(
193
- Query.Transaction({ op: Query.TransactionOperation.Commit, id })
194
- );
195
- return res;
196
- } catch (e) {
197
- await connection.executeQuery(
198
- Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
199
- );
200
- throw e;
201
- } finally {
202
- await release();
203
- }
208
+ return res;
209
+ } catch (e) {
210
+ await connection.executeQuery(
211
+ Query.Transaction({ op: Query.TransactionOperation.Rollback, id })
212
+ );
213
+ throw e;
214
+ } finally {
215
+ await release();
204
216
  }
205
217
  }
206
- Driver2.Async = Async;
207
- class SyncWrapper extends Async {
208
- constructor(sync) {
209
- super(sync.formatter);
210
- this.sync = sync;
211
- }
212
- lock;
213
- async executeQuery(query) {
214
- await this.lock;
215
- return super.executeQuery(query);
216
- }
217
- async rows(stmt) {
218
- return this.sync.rows(stmt);
219
- }
220
- async values(stmt) {
221
- return this.sync.values(stmt);
222
- }
223
- async execute(stmt) {
224
- return this.sync.execute(stmt);
225
- }
226
- async mutate(stmt) {
227
- return this.sync.mutate(stmt);
228
- }
229
- async schemaInstructions(tableName) {
230
- return this.sync.schemaInstructions(tableName);
231
- }
232
- isolate() {
233
- const connection = new SyncWrapper(this.sync);
234
- let release, trigger = new Promise((resolve) => {
235
- release = async () => resolve();
236
- });
237
- this.lock = Promise.resolve(this.lock).then(() => trigger);
238
- return [connection, release];
239
- }
218
+ };
219
+ var SyncWrapper = class extends AsyncDriver {
220
+ constructor(sync) {
221
+ super(sync.formatter);
222
+ this.sync = sync;
223
+ }
224
+ lock;
225
+ async executeQuery(query) {
226
+ await this.lock;
227
+ return super.executeQuery(query);
228
+ }
229
+ async rows(stmt) {
230
+ return this.sync.rows(stmt);
231
+ }
232
+ async values(stmt) {
233
+ return this.sync.values(stmt);
234
+ }
235
+ async execute(stmt) {
236
+ return this.sync.execute(stmt);
237
+ }
238
+ async mutate(stmt) {
239
+ return this.sync.mutate(stmt);
240
240
  }
241
+ async schemaInstructions(tableName) {
242
+ return this.sync.schemaInstructions(tableName);
243
+ }
244
+ isolate() {
245
+ const connection = new SyncWrapper(this.sync);
246
+ let release, trigger = new Promise((resolve) => {
247
+ release = async () => resolve();
248
+ });
249
+ this.lock = Promise.resolve(this.lock).then(() => trigger);
250
+ return [connection, release];
251
+ }
252
+ };
253
+ var Driver;
254
+ ((Driver2) => {
255
+ Driver2.Sync = SyncDriver;
256
+ Driver2.Async = AsyncDriver;
241
257
  })(Driver || (Driver = {}));
242
258
  export {
243
259
  Driver
package/dist/Query.js CHANGED
@@ -58,6 +58,8 @@ var Query;
58
58
  }
59
59
  Query2.Transaction = Transaction;
60
60
  function Raw(raw) {
61
+ if (raw.strings.some((chunk) => chunk.includes("?")))
62
+ throw new TypeError("SQL injection hazard");
61
63
  return { type: "Raw" /* Raw */, ...raw };
62
64
  }
63
65
  Query2.Raw = Raw;
@@ -21,17 +21,13 @@ var BetterSqlite3Driver = class extends Driver.Sync {
21
21
  return { rowsAffected: changes };
22
22
  }
23
23
  schemaInstructions(tableName) {
24
- try {
25
- const columnData = this.rows(
26
- SqliteSchema.tableData(tableName).compile(this.formatter)
27
- );
28
- const indexData = this.rows(
29
- SqliteSchema.indexData(tableName).compile(this.formatter)
30
- );
31
- return SqliteSchema.createInstructions(columnData, indexData);
32
- } catch (e) {
33
- return void 0;
34
- }
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
+ );
30
+ return SqliteSchema.createInstructions(columnData, indexData);
35
31
  }
36
32
  export() {
37
33
  return this.db.serialize();
@@ -31,17 +31,13 @@ var SqlJsDriver = class extends Driver.Sync {
31
31
  return { rowsAffected: this.db.getRowsModified() };
32
32
  }
33
33
  schemaInstructions(tableName) {
34
- try {
35
- const columnData = this.rows(
36
- SqliteSchema.tableData(tableName).compile(this.formatter)
37
- );
38
- const indexData = this.rows(
39
- SqliteSchema.indexData(tableName).compile(this.formatter)
40
- );
41
- return SqliteSchema.createInstructions(columnData, indexData);
42
- } catch (e) {
43
- return void 0;
44
- }
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
+ );
40
+ return SqliteSchema.createInstructions(columnData, indexData);
45
41
  }
46
42
  export() {
47
43
  return this.db.export();
@@ -50,17 +50,13 @@ var Sqlite3Driver = class extends Driver.Async {
50
50
  });
51
51
  }
52
52
  async schemaInstructions(tableName) {
53
- try {
54
- const columnData = await this.rows(
55
- SqliteSchema.tableData(tableName).compile(this.formatter)
56
- );
57
- const indexData = await this.rows(
58
- SqliteSchema.indexData(tableName).compile(this.formatter)
59
- );
60
- return SqliteSchema.createInstructions(columnData, indexData);
61
- } catch (e) {
62
- return void 0;
63
- }
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
+ );
59
+ return SqliteSchema.createInstructions(columnData, indexData);
64
60
  }
65
61
  isolate() {
66
62
  const connection = new Sqlite3Driver(this.db);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './Column';
2
2
  export * from './Cursor';
3
+ export * from './Driver';
3
4
  export * from './Expr';
4
5
  export * from './Fields';
5
6
  export * from './Formatter';
@@ -9,6 +10,7 @@ export * from './OrderBy';
9
10
  export * from './Param';
10
11
  export * from './Query';
11
12
  export * from './Sanitizer';
13
+ export * from './Schema';
12
14
  export * from './Selection';
13
15
  export * from './Statement';
14
16
  export * from './Table';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
  export * from "./Column.js";
3
3
  export * from "./Cursor.js";
4
+ export * from "./Driver.js";
4
5
  export * from "./Expr.js";
5
6
  export * from "./Fields.js";
6
7
  export * from "./Formatter.js";
@@ -10,6 +11,7 @@ export * from "./OrderBy.js";
10
11
  export * from "./Param.js";
11
12
  export * from "./Query.js";
12
13
  export * from "./Sanitizer.js";
14
+ export * from "./Schema.js";
13
15
  export * from "./Selection.js";
14
16
  export * from "./Statement.js";
15
17
  export * from "./Table.js";
@@ -18,7 +18,7 @@ export declare namespace SqliteSchema {
18
18
  }
19
19
  function tableData(tableName: string): Statement;
20
20
  function indexData(tableName: string): Statement;
21
- function createInstructions(columnData: Array<Column>, indexData: Array<Index>): SchemaInstructions;
21
+ function createInstructions(columnData: Array<Column>, indexData: Array<Index>): SchemaInstructions | undefined;
22
22
  function columnInstruction(column: Column): [string, string];
23
23
  function indexInstruction(index: Index): [string, string];
24
24
  }
@@ -13,6 +13,8 @@ var SqliteSchema;
13
13
  }
14
14
  SqliteSchema2.indexData = indexData;
15
15
  function createInstructions(columnData, indexData2) {
16
+ if (columnData.length === 0 && indexData2.length === 0)
17
+ return void 0;
16
18
  const columns = columnData.map(columnInstruction);
17
19
  const indexes = indexData2.map(indexInstruction);
18
20
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {