Last active
August 29, 2015 14:05
-
-
Save alandipert/c6992344f4caea4dc608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; list todos | |
(fn get-todos (shortcode) | |
(let [list-id (code2id shortcode) | |
s "SELECT todo, state FROM todos t INNER JOIN lists l ON t.list_id = l.id WHERE l.id=? ORDER BY t.id" | |
stmt (-> *conn* (prepare s))] | |
(-> stmt (bind_param "i" list-id)) | |
(-> stmt (execute)) | |
(fn fetch (arr) | |
(-> stmt (bind_result todo state)) | |
(if-not (-> stmt (fetch)) | |
(do (-> stmt (close)) | |
arr) | |
(do (array_push arr (arr {"todo" todo "state" state})) | |
(fetch arr)))) | |
(fetch (array)))) | |
(fn type-of (obj) | |
(cond ((is_int obj) "i") | |
((is_double obj) "d") | |
((is_string obj) "s"))) | |
(defmacro binding-params (stmt bindings &body) | |
(let [names (map (get 0) (partition 2 bindings))] | |
`(let ~bindings | |
(-> ~stmt (bind_param (join "" (arr (map #type-of [~@names]))) | |
~@names)) | |
~@body))) | |
(fn prepare (s) | |
(-> *conn* (prepare s))) | |
(let [stmt (prepare "select count(*) from lists where id > ?")] | |
(binding-params stmt | |
[the-id 0] | |
(-> stmt (execute)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHP Fatal error: Call to a member function add_child() on a non-object in /home/alan/projects/pharen/pharen.php on line 3987
PHP Stack trace:
PHP 1. {main}() /home/alan/projects/pharen/bin/pharen:0
PHP 2. compile_file() /home/alan/projects/pharen/bin/pharen:39
PHP 3. compile() /home/alan/projects/pharen/pharen.php:4138
PHP 4. Parser->parse() /home/alan/projects/pharen/pharen.php:4159