|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { SqliteIntrospector } from "data/connection"; |
| 3 | +import { getDummyDatabase } from "../../helper"; |
| 4 | +import { Kysely, SqliteDialect } from "kysely"; |
| 5 | + |
| 6 | +function create() { |
| 7 | + const database = getDummyDatabase().dummyDb; |
| 8 | + return new Kysely({ |
| 9 | + dialect: new SqliteDialect({ database }), |
| 10 | + }); |
| 11 | +} |
| 12 | + |
| 13 | +function createLibsql() { |
| 14 | + const database = getDummyDatabase().dummyDb; |
| 15 | + return new Kysely({ |
| 16 | + dialect: new SqliteDialect({ database }), |
| 17 | + }); |
| 18 | +} |
| 19 | + |
| 20 | +describe("SqliteIntrospector", () => { |
| 21 | + test("asdf", async () => { |
| 22 | + const kysely = create(); |
| 23 | + |
| 24 | + await kysely.schema |
| 25 | + .createTable("test") |
| 26 | + .addColumn("id", "integer", (col) => col.primaryKey().autoIncrement().notNull()) |
| 27 | + .addColumn("string", "text", (col) => col.notNull()) |
| 28 | + .addColumn("number", "integer") |
| 29 | + .execute(); |
| 30 | + |
| 31 | + await kysely.schema |
| 32 | + .createIndex("idx_test_string") |
| 33 | + .on("test") |
| 34 | + .columns(["string"]) |
| 35 | + .unique() |
| 36 | + .execute(); |
| 37 | + |
| 38 | + await kysely.schema |
| 39 | + .createTable("test2") |
| 40 | + .addColumn("id", "integer", (col) => col.primaryKey().autoIncrement().notNull()) |
| 41 | + .addColumn("number", "integer") |
| 42 | + .execute(); |
| 43 | + |
| 44 | + await kysely.schema.createIndex("idx_test2_number").on("test2").columns(["number"]).execute(); |
| 45 | + |
| 46 | + const introspector = new SqliteIntrospector(kysely, {}); |
| 47 | + |
| 48 | + const result = await introspector.getTables(); |
| 49 | + |
| 50 | + //console.log(_jsonp(result)); |
| 51 | + |
| 52 | + expect(result).toEqual([ |
| 53 | + { |
| 54 | + name: "test", |
| 55 | + isView: false, |
| 56 | + columns: [ |
| 57 | + { |
| 58 | + name: "id", |
| 59 | + dataType: "INTEGER", |
| 60 | + isNullable: false, |
| 61 | + isAutoIncrementing: true, |
| 62 | + hasDefaultValue: false, |
| 63 | + comment: undefined, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "string", |
| 67 | + dataType: "TEXT", |
| 68 | + isNullable: false, |
| 69 | + isAutoIncrementing: false, |
| 70 | + hasDefaultValue: false, |
| 71 | + comment: undefined, |
| 72 | + }, |
| 73 | + { |
| 74 | + comment: undefined, |
| 75 | + dataType: "INTEGER", |
| 76 | + hasDefaultValue: false, |
| 77 | + isAutoIncrementing: false, |
| 78 | + isNullable: true, |
| 79 | + name: "number", |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + { |
| 84 | + name: "test2", |
| 85 | + isView: false, |
| 86 | + columns: [ |
| 87 | + { |
| 88 | + name: "id", |
| 89 | + dataType: "INTEGER", |
| 90 | + isNullable: false, |
| 91 | + isAutoIncrementing: true, |
| 92 | + hasDefaultValue: false, |
| 93 | + comment: undefined, |
| 94 | + }, |
| 95 | + { |
| 96 | + name: "number", |
| 97 | + dataType: "INTEGER", |
| 98 | + isNullable: true, |
| 99 | + isAutoIncrementing: false, |
| 100 | + hasDefaultValue: false, |
| 101 | + comment: undefined, |
| 102 | + }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + ]); |
| 106 | + }); |
| 107 | +}); |
0 commit comments