Allow selecting certain columns
This commit is contained in:
parent
f3f0ee0959
commit
c747881d73
|
@ -108,14 +108,12 @@ describe("/v2/views", () => {
|
|||
})
|
||||
|
||||
describe("getSchema", () => {
|
||||
let view: ViewV2
|
||||
|
||||
beforeAll(async () => {
|
||||
await config.createTable(priceTable())
|
||||
view = await config.api.viewV2.create()
|
||||
})
|
||||
|
||||
it("returns table schema if no columns are defined", async () => {
|
||||
const view = await config.api.viewV2.create()
|
||||
const result = await config.api.viewV2.getSchema(view.id)
|
||||
expect(result).toEqual({
|
||||
schema: {
|
||||
|
@ -128,5 +126,19 @@ describe("/v2/views", () => {
|
|||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("respects view column definition if exists", async () => {
|
||||
const view = await config.api.viewV2.create({ columns: ["Category"] })
|
||||
const result = await config.api.viewV2.getSchema(view.id)
|
||||
expect(result).toEqual({
|
||||
schema: {
|
||||
Category: {
|
||||
type: "string",
|
||||
name: "Category",
|
||||
constraints: { type: "string" },
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,6 +3,7 @@ import { TableSchema, View, ViewV2 } from "@budibase/types"
|
|||
|
||||
import sdk from "../../../sdk"
|
||||
import * as utils from "../../../db/utils"
|
||||
import _ from "lodash"
|
||||
|
||||
export async function get(viewId: string): Promise<ViewV2 | undefined> {
|
||||
const { tableId } = utils.extractViewInfoFromID(viewId)
|
||||
|
@ -53,5 +54,10 @@ export async function getSchema(viewId: string): Promise<TableSchema> {
|
|||
const view = await get(viewId)
|
||||
const table = await sdk.tables.getTable(view?.tableId)
|
||||
|
||||
return table.schema
|
||||
if (!view?.columns?.length) {
|
||||
return table.schema
|
||||
}
|
||||
|
||||
const schema = _.pick(table.schema, ...view.columns)
|
||||
return schema
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue