.
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",
|
"name": "eli-vue",
|
||||||
"version": "0.1.183",
|
"version": "0.1.184",
|
||||||
"private": false,
|
"private": false,
|
||||||
"main": "./dist/eli-vue.umd.js",
|
"main": "./dist/eli-vue.umd.js",
|
||||||
"module": "./dist/eli-vue.es.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.
|
* Converte um FiltroDelta opcional em uma cláusula WHERE para o Alasql.
|
||||||
* Cada filtro é convertido individualmente e combinado com AND.
|
* Retorna `"1=1"` (sem filtro) quando `filtros` é `undefined`.
|
||||||
* Retorna `"1=1"` (sem filtro) quando o array é vazio.
|
|
||||||
*
|
*
|
||||||
* @param filtrosArray - Lista de FiltroDelta a combinar; `undefined` ou vazio = sem filtro
|
* @param filtros - FiltroDelta opcional; `undefined` = sem filtro
|
||||||
* @returns Fragmento SQL e array de parâmetros posicionais combinados
|
* @returns Fragmento SQL e array de parâmetros posicionais
|
||||||
*/
|
*/
|
||||||
export const zFiltrosArrayParaAlasql = (
|
export const zFiltrosArrayParaAlasql = (
|
||||||
filtrosArray?: z.infer<typeof zFiltroDelta>[],
|
filtros?: z.infer<typeof zFiltroDelta>,
|
||||||
): { sql: string; parametros: unknown[] } => {
|
): { sql: string; parametros: unknown[] } => {
|
||||||
if (!filtrosArray?.length) return { sql: "1=1", parametros: [] }
|
if (!filtros) return { sql: "1=1", parametros: [] }
|
||||||
|
|
||||||
const queryStrings: string[] = []
|
const { sql, parametros } = zFiltroDeltaParaQuery({ filtros })
|
||||||
const todosParametros: unknown[] = []
|
if (!sql) return { sql: "1=1", parametros: [] }
|
||||||
|
|
||||||
for (const filtro of filtrosArray) {
|
return { sql, parametros }
|
||||||
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 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue