Skip to content

Commit

Permalink
Merge pull request #2537 from aashanand/master
Browse files Browse the repository at this point in the history
Add Date::add and Date::subtract to SQL compiler
  • Loading branch information
pbiggar authored Jun 7, 2020
2 parents e50e2e0 + 7d3bdcc commit c28de56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/libbackend/sql_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let binop_to_sql (op : string) : tipe_ * tipe_ * tipe_ * string =
let allInts str = (TInt, TInt, TInt, str) in
let allFloats str = (TFloat, TFloat, TFloat, str) in
let boolOp tipe str = (tipe, tipe, TBool, str) in
let dateOp str = (TDate, TDate, TDate, str) in
match op with
| ">" | "<" | "<=" | ">=" ->
boolOp TInt op
Expand All @@ -28,6 +29,10 @@ let binop_to_sql (op : string) : tipe_ * tipe_ * tipe_ * string =
boolOp TDate "<="
| "Date::>=" | "Date::greaterThanOrEqualTo" ->
boolOp TDate ">="
| "Date::subtract" ->
dateOp "-"
| "Date::add" ->
dateOp "+"
| "Int::mod" ->
allInts "%"
| "Int::add" ->
Expand Down
18 changes: 18 additions & 0 deletions backend/test/test_db_libs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,24 @@ let t_db_query_works () =
(DList [cat; rachel; chandler])
( queryv (binop "Date::>" (field "v" "dob") (fn "Date::parse" [ross_dob]))
|> execs ) ;
check_dval
"Date::add"
(DList [cat; rachel; chandler; ross])
( queryv
(binop
"Date::<="
(field "v" "dob")
(fn "Date::add" [fn "Date::now" []; int 1]))
|> execs ) ;
check_dval
"Date::subtract"
(DList [cat; rachel; chandler; ross])
( queryv
(binop
"Date::<="
(field "v" "dob")
(fn "Date::subtract" [fn "Date::now" []; int 1]))
|> execs ) ;
check_dval
"string::trim"
(DList [chandler])
Expand Down

0 comments on commit c28de56

Please sign in to comment.