From 9f252f68e03adb0a2b9ad62d3b7ef96fa044495a Mon Sep 17 00:00:00 2001 From: David Botton Date: Wed, 11 May 2022 20:19:27 -0400 Subject: [PATCH] can set timestamp function --- source/clog-data.lisp | 4 ++++ source/clog-web-dbi.lisp | 15 ++++++++------- source/clog.lisp | 5 +++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/source/clog-data.lisp b/source/clog-data.lisp index 99c4c16..e334704 100644 --- a/source/clog-data.lisp +++ b/source/clog-data.lisp @@ -124,6 +124,10 @@ keyword package." ;; Implementation - simple sql writers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defparameter *mysql-timestamp* "unix_timestamp()") +(defparameter *sqlite-timestamp* "strftime('%s')") +(defparameter *postgresql-timestamp* "extract(epoch from now())") + ;;;;;;;;;;;;;;;;;;;; ;; sql-field-list ;; ;;;;;;;;;;;;;;;;;;;; diff --git a/source/clog-web-dbi.lisp b/source/clog-web-dbi.lisp index b99bfa0..87a7dba 100644 --- a/source/clog-web-dbi.lisp +++ b/source/clog-web-dbi.lisp @@ -132,7 +132,7 @@ if one is present and login fails." ;; create-base-table ;; ;;;;;;;;;;;;;;;;;;;;;;; -(defun create-base-tables (sql-connection) +(defun create-base-tables (sql-connection &key (sql-timestamp-func *sqlite-timestamp*)) (dbi:do-sql sql-connection "create table config (key varchar, value varchar)") @@ -149,10 +149,10 @@ if one is present and login fails." "create table users (username varchar, password varchar, token varchar)") (dbi:do-sql sql-connection - (sql-insert* "content" '(:key "main" + (sql-insert* "content" `(:key "main" :title "Welcome to CLOG" :value "Sample data" - :createdate ("date()")))) + :createdate (,sql-timestamp-func)))) (dbi:do-sql sql-connection (sql-insert* "users" `(:username "admin" @@ -203,7 +203,8 @@ optional WHERE and ORDER-BY sql." (can-admin :content-admin) (can-comment :content-comment) (can-show-comments :content-show-comments) - (can-edit :content-edit)) + (can-edit :content-edit) + (sql-timestamp-func *sqlite-timestamp*)) "Create content for CLOG-WEB:CREATE-WEB-PAGE based on dbi TABLE value where key=PAGE or if FOLLOW-URL-PAGE is true PAGE is default page if no second on path otherwise page is the second on path (first @@ -232,7 +233,7 @@ CAN-SHOW-COMMENTS and if CAN-EDIT unless they are set to nil." (list :content pages :do-add (when (clog-auth:is-authorized-p roles can-edit) (lambda (content) - (push '("unixepoch()") content) + (push (list sql-timestamp-func) content) (push :createdate content) (push page content) (push :key content) @@ -275,9 +276,9 @@ CAN-SHOW-COMMENTS and if CAN-EDIT unless they are set to nil." :new-comment (when (clog-auth:is-authorized-p roles can-comment) (lambda (content) - (push '("unixepoch()") content) + (push (list sql-timestamp-func) content) (push :|createdate| content) - (push '("unixepoch()") content) + (push (list sql-timestamp-func) content) (push :|key| content) (push page content) (push :|parent| content) diff --git a/source/clog.lisp b/source/clog.lisp index 2806139..934b901 100644 --- a/source/clog.lisp +++ b/source/clog.lisp @@ -534,6 +534,11 @@ embedded in a native template application.)" (data-write-list function) (data-write-plist function) + "SQL Timestamp by Engine" + (*mysql-timestamp* constant) + (*sqlite-timestamp* constant) + (*postgresql-timestamp* constant) + "SQL Writing Helpers" (sql-quote function) (sql-field-list function)