1
0
Fork 0
mirror of synced 2024-08-23 05:51:29 +12:00

Move boolean coversion down a layer in the stack so it's not tied so directly to search.

This commit is contained in:
Sam Rose 2024-05-07 17:41:43 +01:00
parent 4722fd1cab
commit 39f8727830
No known key found for this signature in database
2 changed files with 22 additions and 7 deletions

View file

@ -150,6 +150,22 @@ function getTableName(table?: Table): string | undefined {
}
}
function convertBooleans(query: SqlQuery | SqlQuery[]): SqlQuery | SqlQuery[] {
if (Array.isArray(query)) {
return query.map((q: SqlQuery) => convertBooleans(q) as SqlQuery)
} else {
if (query.bindings) {
query.bindings = query.bindings.map(binding => {
if (typeof binding === "boolean") {
return binding ? 1 : 0
}
return binding
})
}
}
return query
}
class InternalBuilder {
private readonly client: string
@ -654,7 +670,11 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
if (opts?.disableBindings) {
return { sql: query.toString() }
} else {
return getNativeSql(query)
let native = getNativeSql(query)
if (sqlClient === SqlClient.SQL_LITE) {
native = convertBooleans(native)
}
return native
}
}

View file

@ -165,12 +165,7 @@ export async function search(
}
let sql = query.sql
let bindings = query.bindings?.map(b => {
if (typeof b === "boolean") {
return b ? 1 : 0
}
return b
})
let bindings = query.bindings
// quick hack for docIds
sql = sql.replace(/`doc1`.`rowId`/g, "`doc1.rowId`")