hello / sql / sql.ml

type columns   = All_col | Columns of string list
type condition = And of condition * condition
                 | Or of condition * condition
                 | Not of condition
                 | Gt_f of string * float
                 | Gt_i of string * int
                 | Lt_f of string * float
                 | Lt_i of string * int
                 | Equal_i of string * int
                 | Equal_s of string * string
                 | Regexp  of string * string
  
type query = Select of columns * string * condition list
             (* columns, table *)

let pp_cols = function
  | All_col -> "*";
  | Columns(cols) -> (String.concat "," cols);;

let rec pp_cond = function
  | And(c0, c1) -> (pp_cond c0) ^ " and " ^ (pp_cond c1);
  | Or(c0, c1)  -> (pp_cond c0) ^ " or " ^ (pp_cond c1);
  | Not(c)      -> "(NOT "^(pp_cond c)^")";
  | Gt_f(s, v)  -> Printf.sprintf "(%s < %f)" s v;
  | Gt_i(s, i)  -> Printf.sprintf "(%s < %d)" s i;
  | Lt_f(s, v)  -> Printf.sprintf "(%s > %f)" s v;
  | Lt_i(s, i)  -> Printf.sprintf "(%s > %d)" s i;
  | Equal_i(s, i) -> Printf.sprintf "(%s == %d)" s i;
  | Equal_s(s0,s1)-> Printf.sprintf "(%s == '%s')" s0 s1;
  | Regexp(s,r) -> Printf.sprintf "(%s ~ %s)" s r;;

let rec pp_where = function
  | [] -> "";
  | hd::tl -> (pp_cond hd)^" "^(pp_where tl);;

let pp_query = function
  | Select(columns, table, where) ->
    Printf.printf "select: %s from %s where %s\n" (pp_cols columns) table (pp_where where);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.