in packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts [113:189]
function convertWhereClause(model: string, w?: Where[]) {
if (!w)
return {
and: null,
or: null,
};
const conditions = {
and: [] as any[],
or: [] as any[],
};
w.forEach((condition) => {
let {
field: _field,
value,
operator = "=",
connector = "AND",
} = condition;
const field = getFieldName({ model, field: _field });
value = transformValueToDB(value, model, _field);
const expr = (eb: any) => {
if (operator.toLowerCase() === "in") {
return eb(field, "in", Array.isArray(value) ? value : [value]);
}
if (operator === "contains") {
return eb(field, "like", `%${value}%`);
}
if (operator === "starts_with") {
return eb(field, "like", `${value}%`);
}
if (operator === "ends_with") {
return eb(field, "like", `%${value}`);
}
if (operator === "eq") {
return eb(field, "=", value);
}
if (operator === "ne") {
return eb(field, "<>", value);
}
if (operator === "gt") {
return eb(field, ">", value);
}
if (operator === "gte") {
return eb(field, ">=", value);
}
if (operator === "lt") {
return eb(field, "<", value);
}
if (operator === "lte") {
return eb(field, "<=", value);
}
return eb(field, operator, value);
};
if (connector === "OR") {
conditions.or.push(expr);
} else {
conditions.and.push(expr);
}
});
return {
and: conditions.and.length ? conditions.and : null,
or: conditions.or.length ? conditions.or : null,
};
}