.
This commit is contained in:
parent
2d4d8f8929
commit
aea3da6585
2 changed files with 10 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eli-vue",
|
||||
"version": "0.1.183",
|
||||
"version": "0.1.184",
|
||||
"private": false,
|
||||
"main": "./dist/eli-vue.umd.js",
|
||||
"module": "./dist/eli-vue.es.js",
|
||||
|
|
|
|||
|
|
@ -104,31 +104,21 @@ export const zFiltroDeltaParaQuery = ({
|
|||
}
|
||||
|
||||
/**
|
||||
* Combina um array de FiltroDelta em uma cláusula WHERE única para o Alasql.
|
||||
* Cada filtro é convertido individualmente e combinado com AND.
|
||||
* Retorna `"1=1"` (sem filtro) quando o array é vazio.
|
||||
* Converte um FiltroDelta opcional em uma cláusula WHERE para o Alasql.
|
||||
* Retorna `"1=1"` (sem filtro) quando `filtros` é `undefined`.
|
||||
*
|
||||
* @param filtrosArray - Lista de FiltroDelta a combinar; `undefined` ou vazio = sem filtro
|
||||
* @returns Fragmento SQL e array de parâmetros posicionais combinados
|
||||
* @param filtros - FiltroDelta opcional; `undefined` = sem filtro
|
||||
* @returns Fragmento SQL e array de parâmetros posicionais
|
||||
*/
|
||||
export const zFiltrosArrayParaAlasql = (
|
||||
filtrosArray?: z.infer<typeof zFiltroDelta>[],
|
||||
filtros?: z.infer<typeof zFiltroDelta>,
|
||||
): { sql: string; parametros: unknown[] } => {
|
||||
if (!filtrosArray?.length) return { sql: "1=1", parametros: [] }
|
||||
if (!filtros) return { sql: "1=1", parametros: [] }
|
||||
|
||||
const queryStrings: string[] = []
|
||||
const todosParametros: unknown[] = []
|
||||
const { sql, parametros } = zFiltroDeltaParaQuery({ filtros })
|
||||
if (!sql) return { sql: "1=1", parametros: [] }
|
||||
|
||||
for (const filtro of filtrosArray) {
|
||||
const { sql, parametros } = zFiltroDeltaParaQuery({ filtros: filtro })
|
||||
if (sql) {
|
||||
queryStrings.push(`(${sql})`)
|
||||
todosParametros.push(...parametros)
|
||||
}
|
||||
}
|
||||
|
||||
if (queryStrings.length === 0) return { sql: "1=1", parametros: [] }
|
||||
return { sql: queryStrings.join(" AND "), parametros: todosParametros }
|
||||
return { sql, parametros }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue