I'm using TypedMap for creating a QueryBuilder, so i need to make a { value, field, method } for conditions, and retrieve the correct value relative to method. i'm using a Array MapType
export type WhereConditions<
TablesMap extends { [k: string]: { fields: TablesMap[typeof k] } },
TableName extends keyof TablesMap,
TableFields extends keyof TablesMap[TableName]["fields"]
> = {
[K in TableFields]: {
field: K,
method: TablesMap[TableName]["fields"][K] extends string
? keyof typeof WhereMethods.string
: TablesMap[TableName]["fields"][K] extends Date
? keyof typeof WhereMethods.date
: keyof typeof WhereMethods.number;
value: /* Infer value from method */
}
}[TableFields][]
So, once the QueryBuilder is Called, first is setted the TableName, with a Map we retrieve the fields for select, and optionally, we can make conditions on this call
.from("TECVERDE.EST_PRODUTOS@Tecverde")
.select("nome")
.where(
[
{
field: "nome",
method: "in",
value: /** Expected string[] */
},
{
field: "nome",
method: "equal",
value: /** Expected string */
}
So, if method is in, value can only receive string[], if equal, can only receive string. The WhereReferenceMap is
string:{
equal: (value: string) => `= '${value}'`,
in: (value: string[]) => `IN (${value.map(v => `'${v}'`).join(", ")})`,
}