diff --git a/packages/server/src/integrations/tests/sqlAlias.spec.ts b/packages/server/src/integrations/tests/sqlAlias.spec.ts index 4d39fa7338..647c18d4ae 100644 --- a/packages/server/src/integrations/tests/sqlAlias.spec.ts +++ b/packages/server/src/integrations/tests/sqlAlias.spec.ts @@ -8,6 +8,7 @@ import { TableSchema, Table, TableSourceType, + FieldType, } from "@budibase/types" import { sql } from "@budibase/backend-core" import { join } from "path" @@ -73,8 +74,20 @@ describe("Captures of real examples", () => { }) describe("read", () => { + it("should retrieve all fields if non are specified", () => { + const queryJson = getJson("basicFetch.json") + delete queryJson.resource + + let query = new Sql(SqlClient.POSTGRES)._query(queryJson) + expect(query).toEqual({ + bindings: [primaryLimit], + sql: `select * from "persons" as "a" order by "a"."firstname" asc nulls first, "a"."personid" asc limit $1`, + }) + }) + it("should retrieve only requested fields", () => { const queryJson = getJson("basicFetch.json") + let query = new Sql(SqlClient.POSTGRES)._query(queryJson) expect(query).toEqual({ bindings: [primaryLimit], @@ -82,6 +95,22 @@ describe("Captures of real examples", () => { }) }) + it("should retrieve all fields if a formula column is requested", () => { + const queryJson = getJson("basicFetch.json") + queryJson.table.schema["formula"] = { + name: "formula", + type: FieldType.FORMULA, + formula: "any", + } + queryJson.resource!.fields.push("formula") + + let query = new Sql(SqlClient.POSTGRES)._query(queryJson) + expect(query).toEqual({ + bindings: [primaryLimit], + sql: `select "a".* from "persons" as "a" order by "a"."firstname" asc nulls first, "a"."personid" asc limit $1`, + }) + }) + it("should handle basic retrieval with relationships", () => { const queryJson = getJson("basicFetchWithRelationships.json") let query = new Sql(SqlClient.POSTGRES, relationshipLimit)._query(