mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
initialized postgres support
This commit is contained in:
@@ -15,7 +15,7 @@ describe("SchemaManager tests", async () => {
|
||||
const em = new EntityManager([entity], dummyConnection, [], [index]);
|
||||
const schema = new SchemaManager(em);
|
||||
|
||||
const introspection = schema.getIntrospectionFromEntity(em.entities[0]);
|
||||
const introspection = schema.getIntrospectionFromEntity(em.entities[0]!);
|
||||
expect(introspection).toEqual({
|
||||
name: "test",
|
||||
isView: false,
|
||||
@@ -109,7 +109,7 @@ describe("SchemaManager tests", async () => {
|
||||
await schema.sync({ force: true, drop: true });
|
||||
const diffAfter = await schema.getDiff();
|
||||
|
||||
console.log("diffAfter", diffAfter);
|
||||
//console.log("diffAfter", diffAfter);
|
||||
expect(diffAfter.length).toBe(0);
|
||||
|
||||
await kysely.schema.dropTable(table).execute();
|
||||
|
||||
108
app/__test__/data/specs/connection/SqliteIntrospector.spec.ts
Normal file
108
app/__test__/data/specs/connection/SqliteIntrospector.spec.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import { beforeEach, describe, test, expect } from "bun:test";
|
||||
import { SqliteIntrospector } from "data/connection/SqliteIntrospector";
|
||||
import { getDummyConnection, getDummyDatabase } from "../../helper";
|
||||
import { Kysely, ParseJSONResultsPlugin, SqliteDialect } from "kysely";
|
||||
import { _jsonp } from "core/utils";
|
||||
|
||||
function create() {
|
||||
const database = getDummyDatabase().dummyDb;
|
||||
return new Kysely({
|
||||
dialect: new SqliteDialect({ database }),
|
||||
});
|
||||
}
|
||||
|
||||
function createLibsql() {
|
||||
const database = getDummyDatabase().dummyDb;
|
||||
return new Kysely({
|
||||
dialect: new SqliteDialect({ database }),
|
||||
});
|
||||
}
|
||||
|
||||
describe("SqliteIntrospector", () => {
|
||||
test("asdf", async () => {
|
||||
const kysely = create();
|
||||
|
||||
await kysely.schema
|
||||
.createTable("test")
|
||||
.addColumn("id", "integer", (col) => col.primaryKey().autoIncrement().notNull())
|
||||
.addColumn("string", "text", (col) => col.notNull())
|
||||
.addColumn("number", "integer")
|
||||
.execute();
|
||||
|
||||
await kysely.schema
|
||||
.createIndex("idx_test_string")
|
||||
.on("test")
|
||||
.columns(["string"])
|
||||
.unique()
|
||||
.execute();
|
||||
|
||||
await kysely.schema
|
||||
.createTable("test2")
|
||||
.addColumn("id", "integer", (col) => col.primaryKey().autoIncrement().notNull())
|
||||
.addColumn("number", "integer")
|
||||
.execute();
|
||||
|
||||
await kysely.schema.createIndex("idx_test2_number").on("test2").columns(["number"]).execute();
|
||||
|
||||
const introspector = new SqliteIntrospector(kysely, {});
|
||||
|
||||
const result = await introspector.getTables();
|
||||
|
||||
//console.log(_jsonp(result));
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
name: "test",
|
||||
isView: false,
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
dataType: "INTEGER",
|
||||
isNullable: false,
|
||||
isAutoIncrementing: true,
|
||||
hasDefaultValue: false,
|
||||
comment: undefined,
|
||||
},
|
||||
{
|
||||
name: "string",
|
||||
dataType: "TEXT",
|
||||
isNullable: false,
|
||||
isAutoIncrementing: false,
|
||||
hasDefaultValue: false,
|
||||
comment: undefined,
|
||||
},
|
||||
{
|
||||
comment: undefined,
|
||||
dataType: "INTEGER",
|
||||
hasDefaultValue: false,
|
||||
isAutoIncrementing: false,
|
||||
isNullable: true,
|
||||
name: "number",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
isView: false,
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
dataType: "INTEGER",
|
||||
isNullable: false,
|
||||
isAutoIncrementing: true,
|
||||
hasDefaultValue: false,
|
||||
comment: undefined,
|
||||
},
|
||||
{
|
||||
name: "number",
|
||||
dataType: "INTEGER",
|
||||
isNullable: true,
|
||||
isAutoIncrementing: false,
|
||||
hasDefaultValue: false,
|
||||
comment: undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,23 +1,29 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { Default, parse, stripMark } from "../../../../src/core/utils";
|
||||
import { Field, type SchemaResponse, TextField, baseFieldConfigSchema } from "../../../../src/data";
|
||||
import { runBaseFieldTests, transformPersist } from "./inc";
|
||||
import { Default, stripMark } from "../../../../src/core/utils";
|
||||
import { baseFieldConfigSchema, Field } from "../../../../src/data/fields/Field";
|
||||
import { runBaseFieldTests } from "./inc";
|
||||
|
||||
describe("[data] Field", async () => {
|
||||
class FieldSpec extends Field {
|
||||
schema(): SchemaResponse {
|
||||
return this.useSchemaHelper("text");
|
||||
}
|
||||
getSchema() {
|
||||
return baseFieldConfigSchema;
|
||||
}
|
||||
}
|
||||
|
||||
test("fieldSpec", () => {
|
||||
expect(new FieldSpec("test").schema()).toEqual({
|
||||
name: "test",
|
||||
type: "text",
|
||||
nullable: true, // always true
|
||||
dflt: undefined, // never using default value
|
||||
});
|
||||
});
|
||||
|
||||
runBaseFieldTests(FieldSpec, { defaultValue: "test", schemaType: "text" });
|
||||
|
||||
test("default config", async () => {
|
||||
const config = Default(baseFieldConfigSchema, {});
|
||||
expect(stripMark(new FieldSpec("test").config)).toEqual(config);
|
||||
expect(stripMark(new FieldSpec("test").config)).toEqual(config as any);
|
||||
});
|
||||
|
||||
test("transformPersist (specific)", async () => {
|
||||
|
||||
@@ -10,7 +10,12 @@ describe("[data] PrimaryField", async () => {
|
||||
|
||||
test("schema", () => {
|
||||
expect(field.name).toBe("primary");
|
||||
expect(field.schema()).toEqual(["primary", "integer", expect.any(Function)]);
|
||||
expect(field.schema()).toEqual({
|
||||
name: "primary",
|
||||
type: "integer" as const,
|
||||
nullable: false,
|
||||
primary: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("hasDefault", async () => {
|
||||
|
||||
@@ -34,11 +34,14 @@ export function runBaseFieldTests(
|
||||
|
||||
test("schema", () => {
|
||||
expect(noConfigField.name).toBe("no_config");
|
||||
expect(noConfigField.schema(null as any)).toEqual([
|
||||
"no_config",
|
||||
config.schemaType,
|
||||
expect.any(Function),
|
||||
]);
|
||||
|
||||
const { type, name, nullable, dflt } = noConfigField.schema()!;
|
||||
expect({ type, name, nullable, dflt }).toEqual({
|
||||
type: config.schemaType as any,
|
||||
name: "no_config",
|
||||
nullable: true, // always true
|
||||
dflt: undefined, // never using default value
|
||||
});
|
||||
});
|
||||
|
||||
test("hasDefault", async () => {
|
||||
|
||||
Reference in New Issue
Block a user