wip
This commit is contained in:
parent
4ec7d49d2f
commit
c7c2cb48e8
|
@ -40,13 +40,14 @@ import { structures } from "@budibase/backend-core/tests"
|
|||
import { DEFAULT_EMPLOYEE_TABLE_SCHEMA } from "../../../db/defaultData/datasource_bb_default"
|
||||
|
||||
describe.each([
|
||||
["in-memory", undefined],
|
||||
["lucene", undefined],
|
||||
["sqs", undefined],
|
||||
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
//["in-memory", undefined],
|
||||
//["lucene", undefined],
|
||||
//["sqs", undefined],
|
||||
//[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||
//[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||
//[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||
//[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
|
||||
])("search (%s)", (name, dsProvider) => {
|
||||
const isSqs = name === "sqs"
|
||||
const isLucene = name === "lucene"
|
||||
|
@ -291,7 +292,7 @@ describe.each([
|
|||
})
|
||||
|
||||
describe("equal", () => {
|
||||
it("successfully finds true row", async () => {
|
||||
it.only("successfully finds true row", async () => {
|
||||
await expectQuery({ equal: { isTrue: true } }).toMatchExactly([
|
||||
{ isTrue: true },
|
||||
])
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as mongodb from "./mongodb"
|
|||
import * as mysql from "./mysql"
|
||||
import * as mssql from "./mssql"
|
||||
import * as mariadb from "./mariadb"
|
||||
import * as oracle from "./oracle"
|
||||
import { GenericContainer, StartedTestContainer } from "testcontainers"
|
||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||
import cloneDeep from "lodash/cloneDeep"
|
||||
|
@ -16,6 +17,7 @@ export enum DatabaseName {
|
|||
MYSQL = "mysql",
|
||||
SQL_SERVER = "mssql",
|
||||
MARIADB = "mariadb",
|
||||
ORACLE = "oracle",
|
||||
}
|
||||
|
||||
const providers: Record<DatabaseName, DatasourceProvider> = {
|
||||
|
@ -24,6 +26,7 @@ const providers: Record<DatabaseName, DatasourceProvider> = {
|
|||
[DatabaseName.MYSQL]: mysql.getDatasource,
|
||||
[DatabaseName.SQL_SERVER]: mssql.getDatasource,
|
||||
[DatabaseName.MARIADB]: mariadb.getDatasource,
|
||||
[DatabaseName.ORACLE]: oracle.getDatasource,
|
||||
}
|
||||
|
||||
export function getDatasourceProviders(
|
||||
|
@ -59,6 +62,9 @@ export async function knexClient(ds: Datasource) {
|
|||
case SourceName.SQL_SERVER: {
|
||||
return mssql.knexClient(ds)
|
||||
}
|
||||
case SourceName.ORACLE: {
|
||||
return oracle.knexClient(ds)
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unsupported source: ${ds.source}`)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
import { Datasource, SourceName } from "@budibase/types"
|
||||
import { GenericContainer, Wait } from "testcontainers"
|
||||
import { generator, testContainerUtils } from "@budibase/backend-core/tests"
|
||||
import { startContainer } from "."
|
||||
import knex from "knex"
|
||||
|
||||
let ports: Promise<testContainerUtils.Port[]>
|
||||
|
||||
export async function getDatasource(): Promise<Datasource> {
|
||||
if (!ports) {
|
||||
let image = "oracle/database:19.3.0.0-ee"
|
||||
if (process.arch.startsWith("arm")) {
|
||||
image = "samhuang78/oracle-database:19.3.0-ee-slim-faststart"
|
||||
}
|
||||
|
||||
ports = startContainer(
|
||||
new GenericContainer(image)
|
||||
.withExposedPorts(1521)
|
||||
.withEnvironment({ ORACLE_PASSWORD: "password" })
|
||||
.withWaitStrategy(Wait.forHealthCheck().withStartupTimeout(10000))
|
||||
)
|
||||
}
|
||||
|
||||
const port = (await ports).find(x => x.container === 1521)?.host
|
||||
if (!port) {
|
||||
throw new Error("Oracle port not found")
|
||||
}
|
||||
|
||||
const datasource: Datasource = {
|
||||
type: "datasource_plus",
|
||||
source: SourceName.ORACLE,
|
||||
plus: true,
|
||||
config: {
|
||||
host: "127.0.0.1",
|
||||
port,
|
||||
database: "postgres",
|
||||
user: "SYS",
|
||||
password: "password",
|
||||
},
|
||||
}
|
||||
|
||||
const database = generator.guid().replaceAll("-", "")
|
||||
const client = await knexClient(datasource)
|
||||
await client.raw(`CREATE DATABASE "${database}"`)
|
||||
datasource.config!.database = database
|
||||
|
||||
return datasource
|
||||
}
|
||||
|
||||
export async function knexClient(ds: Datasource) {
|
||||
if (!ds.config) {
|
||||
throw new Error("Datasource config is missing")
|
||||
}
|
||||
if (ds.source !== SourceName.ORACLE) {
|
||||
throw new Error("Datasource source is not Oracle")
|
||||
}
|
||||
|
||||
return knex({
|
||||
client: "oracledb",
|
||||
connection: ds.config,
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue