kysely 0.11.0 → 0.11.1

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.
@@ -12,18 +12,31 @@ class SqliteIntrospector {
12
12
  .selectFrom('sqlite_schema')
13
13
  .where('type', '=', 'table')
14
14
  .where('name', 'not like', 'sqlite_%')
15
- .select('name');
15
+ .select('name')
16
+ .castTo();
16
17
  if (!options.withInternalKyselyTables) {
17
18
  query = query
18
19
  .where('name', '!=', migration_js_1.MIGRATION_TABLE)
19
20
  .where('name', '!=', migration_js_1.MIGRATION_LOCK_TABLE);
20
21
  }
21
- const result = await query.execute();
22
+ const tables = await query.execute();
22
23
  return {
23
- tables: result.map((it) => ({
24
- name: it.name,
25
- // TODO: Get columns somehow.
26
- columns: [],
24
+ tables: await Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))),
25
+ };
26
+ }
27
+ async #getTableMetadata(table) {
28
+ const db = this.#db;
29
+ const columns = await db
30
+ .selectFrom(db.raw(`PRAGMA_TABLE_INFO(?)`, [table]).as('table_info'))
31
+ .select(['name', 'type', 'notnull'])
32
+ .castTo()
33
+ .execute();
34
+ return {
35
+ name: table,
36
+ columns: columns.map((col) => ({
37
+ name: col.name,
38
+ dataType: col.type,
39
+ isNullable: !col.notnull,
27
40
  })),
28
41
  };
29
42
  }
@@ -9,18 +9,31 @@ export class SqliteIntrospector {
9
9
  .selectFrom('sqlite_schema')
10
10
  .where('type', '=', 'table')
11
11
  .where('name', 'not like', 'sqlite_%')
12
- .select('name');
12
+ .select('name')
13
+ .castTo();
13
14
  if (!options.withInternalKyselyTables) {
14
15
  query = query
15
16
  .where('name', '!=', MIGRATION_TABLE)
16
17
  .where('name', '!=', MIGRATION_LOCK_TABLE);
17
18
  }
18
- const result = await query.execute();
19
+ const tables = await query.execute();
19
20
  return {
20
- tables: result.map((it) => ({
21
- name: it.name,
22
- // TODO: Get columns somehow.
23
- columns: [],
21
+ tables: await Promise.all(tables.map(({ name }) => this.#getTableMetadata(name))),
22
+ };
23
+ }
24
+ async #getTableMetadata(table) {
25
+ const db = this.#db;
26
+ const columns = await db
27
+ .selectFrom(db.raw(`PRAGMA_TABLE_INFO(?)`, [table]).as('table_info'))
28
+ .select(['name', 'type', 'notnull'])
29
+ .castTo()
30
+ .execute();
31
+ return {
32
+ name: table,
33
+ columns: columns.map((col) => ({
34
+ name: col.name,
35
+ dataType: col.type,
36
+ isNullable: !col.notnull,
24
37
  })),
25
38
  };
26
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kysely",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Type safe SQL query builder",
5
5
  "repository": {
6
6
  "type": "git",