Skip to content

Commit

Permalink
Merge branch 'master' into BUDI-8508/sql-support-for-logical-operators
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Aug 6, 2024
2 parents 99a0261 + e16929b commit ab54218
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
61 changes: 49 additions & 12 deletions packages/server/src/api/routes/tests/datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ import {
SupportedSqlTypes,
JsonFieldSubType,
} from "@budibase/types"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
import {
DatabaseName,
getDatasource,
knexClient,
} from "../../../integrations/tests/utils"
import { tableForDatasource } from "../../../tests/utilities/structures"
import nock from "nock"
import { Knex } from "knex"

describe("/datasources", () => {
const config = setup.getConfig()
Expand Down Expand Up @@ -167,9 +172,12 @@ describe("/datasources", () => {
[DatabaseName.ORACLE, getDatasource(DatabaseName.ORACLE)],
])("%s", (_, dsProvider) => {
let rawDatasource: Datasource
let client: Knex

beforeEach(async () => {
rawDatasource = await dsProvider
datasource = await config.api.datasource.create(rawDatasource)
client = await knexClient(rawDatasource)
})

describe("get", () => {
Expand Down Expand Up @@ -435,20 +443,49 @@ describe("/datasources", () => {
})

describe("info", () => {
it("should fetch information about a datasource", async () => {
const table = await config.api.table.save(
tableForDatasource(datasource, {
schema: {
name: {
name: "name",
type: FieldType.STRING,
},
},
})
it("should fetch information about a datasource with a single table", async () => {
const existingTableNames = (
await config.api.datasource.info(datasource)
).tableNames

const tableName = generator.guid()
await client.schema.createTable(tableName, table => {
table.increments("id").primary()
table.string("name")
})

const info = await config.api.datasource.info(datasource)
expect(info.tableNames).toEqual(
expect.arrayContaining([tableName, ...existingTableNames])
)
expect(info.tableNames).toHaveLength(existingTableNames.length + 1)
})

it("should fetch information about a datasource with multiple tables", async () => {
const existingTableNames = (
await config.api.datasource.info(datasource)
).tableNames

const tableNames = [
generator.guid(),
generator.guid(),
generator.guid(),
generator.guid(),
]
for (const tableName of tableNames) {
await client.schema.createTable(tableName, table => {
table.increments("id").primary()
table.string("name")
})
}

const info = await config.api.datasource.info(datasource)
expect(info.tableNames).toContain(table.name)
expect(info.tableNames).toEqual(
expect.arrayContaining([...tableNames, ...existingTableNames])
)
expect(info.tableNames).toHaveLength(
existingTableNames.length + tableNames.length
)
})
})
})
Expand Down
6 changes: 5 additions & 1 deletion packages/server/src/integrations/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ class OracleIntegration extends Sql implements DatasourcePlus {
const columnsResponse = await this.internalQuery<OracleColumnsResponse>({
sql: OracleIntegration.COLUMNS_SQL,
})
return (columnsResponse.rows || []).map(row => row.TABLE_NAME)
const tableNames = new Set<string>()
for (const row of columnsResponse.rows || []) {
tableNames.add(row.TABLE_NAME)
}
return Array.from(tableNames)
}

async testConnection() {
Expand Down

0 comments on commit ab54218

Please sign in to comment.