Skip to content
56 changes: 55 additions & 1 deletion src/driver/cratedb/CrateDBPostgresDriver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Driver } from "../Driver"
import { PostgresDriver } from "../postgres/PostgresDriver"
import { CrateDBPostgresConnectionOptions } from "./CrateDBPostgresConnectionOptions";

import { ColumnType } from "../types/ColumnTypes"
import { QueryRunner } from "../../query-runner/QueryRunner"
import { ReplicationMode } from "../types/ReplicationMode"
import { CrateDBPostgresQueryRunner } from "./CrateDBPostgresQueryRunner"

abstract class PostgresWrapper extends PostgresDriver {
options: any
Expand Down Expand Up @@ -32,4 +35,55 @@ export class CrateDBPostgresDriver extends PostgresWrapper implements Driver {
return "gen_random_text_uuid()"
}

createQueryRunner(mode: ReplicationMode): QueryRunner {
return new CrateDBPostgresQueryRunner(this, mode)
}

normalizeType(column: {
type: ColumnType
length?: number | string
precision?: number | null
scale?: number
}): string {
if (column.type === Number || column.type === "integer") {
return "int"
} else if (column.type === String) {
return "text"
} else if (column.type === Date) {
return "timestamp"
} else if (column.type === Boolean) {
return "boolean"
} else if (column.type === "uuid") {
return "text"
} else if (column.type === "json") {
return "object"
} else if (column.type === "simple-array") {
return "array(text)"
} else if (
column.type === "double precision" ||
column.type === "real"
) {
return "double"
} else if (
column.type === "dec" ||
column.type === "numeric" ||
column.type === "fixed"
) {
return "double"
} else if (column.type === "bool" || column.type === "boolean") {
return "boolean"
} else if (
column.type === "nvarchar" ||
column.type === "national varchar"
) {
return "text"
} else if (column.type === "nchar" || column.type === "national char") {
return "text"
} else if ( ((column.type as string) || "") === "") {
return "text"
} else {
return (column.type as string) || ""
}
}

}
Loading