import { Col, colUnwrap, colWrap } from "./Column"; import { BinOp } from "./Exp"; import { SqlType } from "./SqlType"; export function e(lhs: Col, op: "=", rhs: Col): Col; export function e(lhs: Col, op: "!=", rhs: Col): Col; export function e(lhs: Col, op: ">", rhs: Col): Col; export function e(lhs: Col, op: "<", rhs: Col): Col; export function e(lhs: Col, op: ">=", rhs: Col): Col; export function e(lhs: Col, op: "<=", rhs: Col): Col; export function e(lhs: Col, op: "AND", rhs: Col): Col; export function e(lhs: Col, op: "OR", rhs: Col): Col; export function e(lhs: Col, op: "+", rhs: Col): Col; export function e(lhs: Col, op: "-", rhs: Col): Col; export function e(lhs: Col, op: "*", rhs: Col): Col; export function e(lhs: Col, op: "/", rhs: Col): Col; export function e(lhs: Col, op: "||", rhs: Col): Col; export function e(lhs: any, op: string, rhs: any): any { switch (op) { case "=": return colWrap({ type: "EBinOp", op: BinOp.Eq, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "!=": return colWrap({ type: "EBinOp", op: BinOp.Neq, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case ">": return colWrap({ type: "EBinOp", op: BinOp.Gt, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "<": return colWrap({ type: "EBinOp", op: BinOp.Lt, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case ">=": return colWrap({ type: "EBinOp", op: BinOp.Gte, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "<=": return colWrap({ type: "EBinOp", op: BinOp.Lte, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "AND": return colWrap({ type: "EBinOp", op: BinOp.And, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "OR": return colWrap({ type: "EBinOp", op: BinOp.Or, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.booleanParser }); case "+": return colWrap({ type: "EBinOp", op: BinOp.Add, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.numberParser }); case "-": return colWrap({ type: "EBinOp", op: BinOp.Sub, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.numberParser }); case "*": return colWrap({ type: "EBinOp", op: BinOp.Mul, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.numberParser }); case "/": return colWrap({ type: "EBinOp", op: BinOp.Div, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.numberParser }); case "||": return colWrap({ type: "EBinOp", op: BinOp.Concat, lhs: colUnwrap(lhs), rhs: colUnwrap(rhs), parser: SqlType.stringParser }); /* istanbul ignore next */ default: throw new Error(`The Impossible Happened. Unexpected op: "${op}"`); } }