_comuns/src/consulta.ts
2026-04-15 12:24:38 -03:00

40 lines
752 B
TypeScript
Executable file

import z from "zod"
export enum operadores {
"=" = "=",
"!=" = "!=",
">" = ">",
">=" = ">=",
"<" = "<",
"<=" = "<=",
like = "like",
in = "in",
isNull = "isNull",
}
export type tipoFiltro = {
coluna: string
valor: any
operador: keyof typeof operadores | operadores
ou?: boolean
}
export type interfaceConsulta = {
offset?: number
limit?: number
filtros?: tipoFiltro[]
ordem?: string
ordemTipo?: "asc" | "desc"
colunas?: string[]
apenasConsulta?: boolean
apenasContagem?: boolean
}
export const zOperadores = z.enum(["=", "!=", ">", ">=", "<", "<=", "like", "in", "isNull"])
export const zFiltro = z.object({
coluna: z.string(),
valor: z.any(),
operador: zOperadores,
ou: z.boolean().optional(),
})