Use raw sql to get money type as numeric
This commit is contained in:
parent
f8fa52f1b9
commit
8154fe3445
|
@ -12,6 +12,7 @@ export interface Application extends Base {
|
||||||
export interface FieldSchema {
|
export interface FieldSchema {
|
||||||
// TODO: replace with field types enum when done
|
// TODO: replace with field types enum when done
|
||||||
type: string
|
type: string
|
||||||
|
externalType?: string
|
||||||
fieldName?: string
|
fieldName?: string
|
||||||
name: string
|
name: string
|
||||||
tableId?: string
|
tableId?: string
|
||||||
|
|
|
@ -89,6 +89,24 @@ function parseFilters(filters: SearchFilters | undefined): SearchFilters {
|
||||||
return filters
|
return filters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateSelectStatement(json: QueryJson, knex: Knex): any[] {
|
||||||
|
const { resource, meta } = json
|
||||||
|
const schema = meta?.table?.schema
|
||||||
|
return resource.fields.map(field => {
|
||||||
|
const shortFieldName = field.match(/(?<=\.).*$/g)?.[0]
|
||||||
|
if (shortFieldName) {
|
||||||
|
const externalType = schema?.[shortFieldName].externalType
|
||||||
|
if (externalType?.includes("money")) {
|
||||||
|
const fieldName = field.split(/\./g)
|
||||||
|
return knex.raw(
|
||||||
|
`"${fieldName?.[0]}"."${fieldName?.[1]}"::money::numeric as "${field}"`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `${field} as ${field}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
class InternalBuilder {
|
class InternalBuilder {
|
||||||
private readonly client: string
|
private readonly client: string
|
||||||
|
|
||||||
|
@ -323,12 +341,12 @@ class InternalBuilder {
|
||||||
if (!resource) {
|
if (!resource) {
|
||||||
resource = { fields: [] }
|
resource = { fields: [] }
|
||||||
}
|
}
|
||||||
let selectStatement: string | string[] = "*"
|
let selectStatement: string | any[] = "*"
|
||||||
// handle select
|
// handle select
|
||||||
if (resource.fields && resource.fields.length > 0) {
|
if (resource.fields && resource.fields.length > 0) {
|
||||||
// select the resources as the format "table.columnName" - this is what is provided
|
// select the resources as the format "table.columnName" - this is what is provided
|
||||||
// by the resource builder further up
|
// by the resource builder further up
|
||||||
selectStatement = resource.fields.map(field => `${field} as ${field}`)
|
selectStatement = generateSelectStatement(json, knex)
|
||||||
}
|
}
|
||||||
let foundLimit = limit || BASE_LIMIT
|
let foundLimit = limit || BASE_LIMIT
|
||||||
// handle pagination
|
// handle pagination
|
||||||
|
|
|
@ -1094,11 +1094,12 @@
|
||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@budibase/backend-core@1.0.207-alpha.3":
|
"@budibase/backend-core@1.0.207-alpha.6":
|
||||||
version "1.0.207-alpha.3"
|
version "1.0.207-alpha.6"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.207-alpha.3.tgz#98bced0575ec4e2b158239a8c73b39ca2d816719"
|
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.207-alpha.6.tgz#47fed5cc78686e23951a050479c777673f725c17"
|
||||||
integrity sha512-DU4X6jJ+DfhzOv4TTa1w4Dk5ZEdlK/z1joCTruT+SGM5qI75bXrGeol5OX2OaEbNKtXFKJ1zeVTmBCYcu7OFUg==
|
integrity sha512-mB3i9TyNbdlE8TmsAWGXhphwLRlrBd2bDfvOYTz3CP7xzql1FXGoWfOqA87vNaGBDrtOyQQnmbYeTc3Tn2OHcg==
|
||||||
dependencies:
|
dependencies:
|
||||||
|
"@budibase/types" "^1.0.207-alpha.6"
|
||||||
"@techpass/passport-openidconnect" "0.3.2"
|
"@techpass/passport-openidconnect" "0.3.2"
|
||||||
aws-sdk "2.1030.0"
|
aws-sdk "2.1030.0"
|
||||||
bcrypt "5.0.1"
|
bcrypt "5.0.1"
|
||||||
|
@ -1175,12 +1176,12 @@
|
||||||
svelte-flatpickr "^3.2.3"
|
svelte-flatpickr "^3.2.3"
|
||||||
svelte-portal "^1.0.0"
|
svelte-portal "^1.0.0"
|
||||||
|
|
||||||
"@budibase/pro@1.0.207-alpha.3":
|
"@budibase/pro@1.0.207-alpha.6":
|
||||||
version "1.0.207-alpha.3"
|
version "1.0.207-alpha.6"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.207-alpha.3.tgz#9bde845ceb685f1b43286a124620c21fdf891a01"
|
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.207-alpha.6.tgz#04a81281beeb230c0c1a1f48237a94e1150a7851"
|
||||||
integrity sha512-WFEMujpKTVAMvAgLBnMdw8ou9PxsbM4Oa9Dq+DAUsWpPACsMWOProyHLsdRxJyvHlgGfwVjo5MEusvStjI4j6g==
|
integrity sha512-IDQdKHaojfGlL8xLSQ1gYrLyipgUYPJ6Mjrrp8TcWnpwTOA2Wtzen31E5HG6YxZU8g8rN6k9S0Nsp88JKOGSrg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@budibase/backend-core" "1.0.207-alpha.3"
|
"@budibase/backend-core" "1.0.207-alpha.6"
|
||||||
node-fetch "^2.6.1"
|
node-fetch "^2.6.1"
|
||||||
|
|
||||||
"@budibase/standard-components@^0.9.139":
|
"@budibase/standard-components@^0.9.139":
|
||||||
|
@ -1201,6 +1202,11 @@
|
||||||
svelte-apexcharts "^1.0.2"
|
svelte-apexcharts "^1.0.2"
|
||||||
svelte-flatpickr "^3.1.0"
|
svelte-flatpickr "^3.1.0"
|
||||||
|
|
||||||
|
"@budibase/types@^1.0.207-alpha.6":
|
||||||
|
version "1.0.208"
|
||||||
|
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.0.208.tgz#c45cb494fb5b85229e15a34c6ac1805bae5be867"
|
||||||
|
integrity sha512-zKIHg6TGK+soVxMNZNrGypP3DCrd3jhlUQEFeQ+rZR6/tCue1G74bjzydY5FjnLEsXeLH1a0hkS5HulTmvQ2bA==
|
||||||
|
|
||||||
"@bull-board/api@3.7.0":
|
"@bull-board/api@3.7.0":
|
||||||
version "3.7.0"
|
version "3.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-3.7.0.tgz#231f687187c0cb34e0b97f463917b6aaeb4ef6af"
|
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-3.7.0.tgz#231f687187c0cb34e0b97f463917b6aaeb4ef6af"
|
||||||
|
|
Loading…
Reference in New Issue