diff src/sql.sml @ 2213:365727ff68f4

Complete overhaul: cache queries based on immediate query result, not eventual HTML output.
author Ziv Scully <ziv@mit.edu>
date Tue, 14 Oct 2014 18:05:09 -0400
parents ef766ef6e242
children 639e62ca2530
line wrap: on
line diff
--- a/src/sql.sml	Mon Sep 15 20:01:16 2014 -0400
+++ b/src/sql.sml	Tue Oct 14 18:05:09 2014 -0400
@@ -270,6 +270,22 @@
 
       | _ => NONE
 
+fun sqlifySqlcache chs =
+    case chs of
+        (* Match entire FFI application, not just its argument. *)
+        Exp (e' as EFfiApp ("Basis", f, [(_, _)]), _) :: chs =>
+        if String.isPrefix "sqlify" f then
+            SOME ((e', ErrorMsg.dummySpan), chs)
+        else
+            NONE
+      | Exp (ECase (e, [((PCon (_, PConFfi {mod = "Basis", con = "True", ...}, NONE), _),
+                         (EPrim (Prim.String (Prim.Normal, "TRUE")), _)),
+                        ((PCon (_, PConFfi {mod = "Basis", con = "False", ...}, NONE), _),
+                         (EPrim (Prim.String (Prim.Normal, "FALSE")), _))], _), _) :: chs =>
+        SOME (e, chs)
+
+      | _ => NONE
+
 fun constK s = wrap (const s) (fn () => s)
 
 val funcName = altL [constK "COUNT",
@@ -281,6 +297,8 @@
 val unmodeled = altL [const "COUNT(*)",
                       const "CURRENT_TIMESTAMP"]
 
+val sqlcacheMode = ref false;
+
 fun sqexp chs =
     log "sqexp"
     (altL [wrap prim SqConst,
@@ -292,7 +310,7 @@
            wrap known SqKnown,
            wrap func SqFunc,
            wrap unmodeled (fn () => Unmodeled),
-           wrap sqlify Inj,
+           wrap (if !sqlcacheMode then sqlifySqlcache else sqlify) Inj,
            wrap (follow (const "COALESCE(") (follow sqexp (follow (const ",")
                                                                   (follow (keep (fn ch => ch <> #")")) (const ")")))))
                 (fn ((), (e, _)) => e),