Has any support SQL Server

This commit is contained in:
Mel O'Hagan 2022-07-28 09:20:00 +01:00
parent 7664984d7b
commit 2356d09022
4 changed files with 53 additions and 52 deletions

View File

@ -193,20 +193,21 @@ class InternalBuilder {
) )
}) })
} else { } else {
const andOr = mode === filters?.containsAny ? " OR " : " AND "
iterate(mode, (key: string, value: Array<any>) => { iterate(mode, (key: string, value: Array<any>) => {
let andStatement = "" let statement = ""
for (let i in value) { for (let i in value) {
if (typeof value[i] === "string") { if (typeof value[i] === "string") {
value[i] = `%"${value[i]}"%` value[i] = `%"${value[i]}"%`
} else { } else {
value[i] = `%${value[i]}%` value[i] = `%${value[i]}%`
} }
andStatement += statement +=
(andStatement ? " AND " : "") + (statement ? andOr : "") +
`LOWER(${likeKey(this.client, key)}) LIKE ?` `LOWER(${likeKey(this.client, key)}) LIKE ?`
} }
// @ts-ignore // @ts-ignore
query = query[rawFnc](`${not}(${andStatement})`, value) query = query[rawFnc](`${not}(${statement})`, value)
}) })
} }
} }

View File

@ -240,18 +240,18 @@ describe("SQL query builder", () => {
}) })
}) })
it("should use like expression for MS-SQL when filter is contains", () => { it("should use AND like expression for MS-SQL when filter is contains", () => {
const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({
filters: { filters: {
contains: { contains: {
age: [20], age: [20, 25],
name: ["John"] name: ["John", "Mary"]
} }
} }
})) }))
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "%20%", `%"John"%`], bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1) and (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 AND LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 AND LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]`
}) })
}) })
@ -330,18 +330,18 @@ describe("SQL query builder", () => {
}) })
}) })
it("should use like expression for MS-SQL when filter is containsAny", () => { it("should use OR like expression for MS-SQL when filter is containsAny", () => {
const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({ const query = new Sql(SqlClients.MS_SQL, 10)._query(generateReadJson({
filters: { filters: {
containsAny: { containsAny: {
age: [20], age: [20, 25],
name: ["John"] name: ["John", "Mary"]
} }
} }
})) }))
expect(query).toEqual({ expect(query).toEqual({
bindings: [10, "%20%", `%"John"%`], bindings: [10, "%20%", "%25%", `%"John"%`, `%"Mary"%`],
sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1) and (LOWER(${TABLE_NAME}.name) LIKE @p2)) as [${TABLE_NAME}]` sql: `select * from (select top (@p0) * from [${TABLE_NAME}] where (LOWER(${TABLE_NAME}.age) LIKE @p1 OR LOWER(${TABLE_NAME}.age) LIKE @p2) and (LOWER(${TABLE_NAME}.name) LIKE @p3 OR LOWER(${TABLE_NAME}.name) LIKE @p4)) as [${TABLE_NAME}]`
}) })
}) })

View File

@ -1094,12 +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.1.25-alpha.2": "@budibase/backend-core@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25-alpha.2.tgz#363d8d66378d405b7a4deb754709f181348cf54d" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25-alpha.3.tgz#59906d13874f37e90420051f1c03ecffa74619fa"
integrity sha512-qcnTToh1CN8FXWg0n6V/396pzhRurzIMD9imcVAiXUzQgMa13EAZ137kkvAPwklrKJiv0Afw0i+9hDddCGXlyQ== integrity sha512-LuA9DN3P5Dp8rlm3Lp6Fnggye/5vmbp2gM05swQcoZ2pzG4mN8b+XD/U5Y1bxss7pK8YDnf5kyb+Ido/63u0KQ==
dependencies: dependencies:
"@budibase/types" "^1.1.25-alpha.2" "@budibase/types" "^1.1.25-alpha.3"
"@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"
@ -1177,13 +1177,13 @@
svelte-flatpickr "^3.2.3" svelte-flatpickr "^3.2.3"
svelte-portal "^1.0.0" svelte-portal "^1.0.0"
"@budibase/pro@1.1.25-alpha.2": "@budibase/pro@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25-alpha.2.tgz#652eb2c2ad13ae8ae4a34975a7407d53c8be574d" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25-alpha.3.tgz#6d353ab2f1e0cf0705d0a0e9ba6778b085c41fa9"
integrity sha512-ULmehYmSChe9F7qXrv0QvIH80skIoSQnmtxa492CLB/eQxDYYJj8g7xowcy+tM5qFEe1dkvsH1x/gEv9r8FtHw== integrity sha512-2YgC0HwCyfQrZnueUAnQ4SUyDcg0n6hiUsnxCuaPKJ4A1T06AcQnAIs15JN/5JB+YVCQn3fs/eSC9p8JLwkX/A==
dependencies: dependencies:
"@budibase/backend-core" "1.1.25-alpha.2" "@budibase/backend-core" "1.1.25-alpha.3"
"@budibase/types" "1.1.25-alpha.2" "@budibase/types" "1.1.25-alpha.3"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
joi "17.6.0" joi "17.6.0"
node-fetch "^2.6.1" node-fetch "^2.6.1"
@ -1206,15 +1206,15 @@
svelte-apexcharts "^1.0.2" svelte-apexcharts "^1.0.2"
svelte-flatpickr "^3.1.0" svelte-flatpickr "^3.1.0"
"@budibase/types@1.1.25-alpha.2": "@budibase/types@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25-alpha.2.tgz#9b054df56c169ea86598ddeb777cf16bd5b3858d" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25-alpha.3.tgz#3282b8487d63968872cdafa7c35c1e4eefd1d54c"
integrity sha512-eWd4OB4fuSXkoFLOZrkg0UWu6otsATj7HPZ+9wKgW+wY4CXUYdbLXvfda05nsnogN/QtbyVvGOn7kfZI4AiNGg== integrity sha512-kQijeWXWYpL6qcXjo/NCASHW9Y3sT9hSUlBBJKs7cPjZx/z+qXWjxd4nxHGmZRG5w1iPNSEsCjBkQGmIdx9tNQ==
"@budibase/types@^1.1.25-alpha.2": "@budibase/types@^1.1.25-alpha.3":
version "1.1.27" version "1.1.28"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.27.tgz#6a9609c83cac1c3d4e5f1bfde856ba2d7b6f1db3" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.28.tgz#def0f3cd931f9b688dc5a2a479f3b82c8f0be8b1"
integrity sha512-pWY5ywAGqoSXdRVvuztMQqwG6qCwc4rR3tPZ82W1HVHrC1h1e5+oqVAwMvQECh1T8jB6WrrotjaSNWHXGvQF+A== integrity sha512-U2W6aa/N2SpSZaQiWJ25GXgiIBHVtaeORa9a+07t4Z9AhHYoATGnnLcw842Fsko3KgIcuI6HZT8acbVz1BP4CQ==
"@bull-board/api@3.7.0": "@bull-board/api@3.7.0":
version "3.7.0" version "3.7.0"

View File

@ -291,12 +291,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.1.25-alpha.2": "@budibase/backend-core@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25-alpha.2.tgz#363d8d66378d405b7a4deb754709f181348cf54d" resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.1.25-alpha.3.tgz#59906d13874f37e90420051f1c03ecffa74619fa"
integrity sha512-qcnTToh1CN8FXWg0n6V/396pzhRurzIMD9imcVAiXUzQgMa13EAZ137kkvAPwklrKJiv0Afw0i+9hDddCGXlyQ== integrity sha512-LuA9DN3P5Dp8rlm3Lp6Fnggye/5vmbp2gM05swQcoZ2pzG4mN8b+XD/U5Y1bxss7pK8YDnf5kyb+Ido/63u0KQ==
dependencies: dependencies:
"@budibase/types" "^1.1.25-alpha.2" "@budibase/types" "^1.1.25-alpha.3"
"@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"
@ -324,26 +324,26 @@
uuid "8.3.2" uuid "8.3.2"
zlib "1.0.5" zlib "1.0.5"
"@budibase/pro@1.1.25-alpha.2": "@budibase/pro@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25-alpha.2.tgz#652eb2c2ad13ae8ae4a34975a7407d53c8be574d" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.1.25-alpha.3.tgz#6d353ab2f1e0cf0705d0a0e9ba6778b085c41fa9"
integrity sha512-ULmehYmSChe9F7qXrv0QvIH80skIoSQnmtxa492CLB/eQxDYYJj8g7xowcy+tM5qFEe1dkvsH1x/gEv9r8FtHw== integrity sha512-2YgC0HwCyfQrZnueUAnQ4SUyDcg0n6hiUsnxCuaPKJ4A1T06AcQnAIs15JN/5JB+YVCQn3fs/eSC9p8JLwkX/A==
dependencies: dependencies:
"@budibase/backend-core" "1.1.25-alpha.2" "@budibase/backend-core" "1.1.25-alpha.3"
"@budibase/types" "1.1.25-alpha.2" "@budibase/types" "1.1.25-alpha.3"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
joi "17.6.0" joi "17.6.0"
node-fetch "^2.6.1" node-fetch "^2.6.1"
"@budibase/types@1.1.25-alpha.2": "@budibase/types@1.1.25-alpha.3":
version "1.1.25-alpha.2" version "1.1.25-alpha.3"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25-alpha.2.tgz#9b054df56c169ea86598ddeb777cf16bd5b3858d" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.25-alpha.3.tgz#3282b8487d63968872cdafa7c35c1e4eefd1d54c"
integrity sha512-eWd4OB4fuSXkoFLOZrkg0UWu6otsATj7HPZ+9wKgW+wY4CXUYdbLXvfda05nsnogN/QtbyVvGOn7kfZI4AiNGg== integrity sha512-kQijeWXWYpL6qcXjo/NCASHW9Y3sT9hSUlBBJKs7cPjZx/z+qXWjxd4nxHGmZRG5w1iPNSEsCjBkQGmIdx9tNQ==
"@budibase/types@^1.1.25-alpha.2": "@budibase/types@^1.1.25-alpha.3":
version "1.1.27" version "1.1.28"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.27.tgz#6a9609c83cac1c3d4e5f1bfde856ba2d7b6f1db3" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-1.1.28.tgz#def0f3cd931f9b688dc5a2a479f3b82c8f0be8b1"
integrity sha512-pWY5ywAGqoSXdRVvuztMQqwG6qCwc4rR3tPZ82W1HVHrC1h1e5+oqVAwMvQECh1T8jB6WrrotjaSNWHXGvQF+A== integrity sha512-U2W6aa/N2SpSZaQiWJ25GXgiIBHVtaeORa9a+07t4Z9AhHYoATGnnLcw842Fsko3KgIcuI6HZT8acbVz1BP4CQ==
"@cspotcode/source-map-consumer@0.8.0": "@cspotcode/source-map-consumer@0.8.0":
version "0.8.0" version "0.8.0"