diff options
author | 2013-03-20 21:58:10 +0100 | |
---|---|---|
committer | 2013-03-20 21:58:10 +0100 | |
commit | 94f56cd473dfc950c9263753d3a991b92eff128e (patch) | |
tree | 3a57bc39ad91b2f698835823b550ba8baa84527f /clark.lisp | |
download | clark-94f56cd473dfc950c9263753d3a991b92eff128e.tar.gz clark-94f56cd473dfc950c9263753d3a991b92eff128e.zip |
Initial commit
Diffstat (limited to 'clark.lisp')
-rw-r--r-- | clark.lisp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/clark.lisp b/clark.lisp new file mode 100644 index 0000000..c233a5a --- /dev/null +++ b/clark.lisp @@ -0,0 +1,39 @@ +(in-package :org.ryuslash.clark) + +(export '(clark)) + +(defvar *db* nil + "The database connection.") + +(defun db-connect (name) + "Connect to the database, possibly creating it." + (let ((db-exists (probe-file name))) + (connect (list name) :database-type :sqlite3) + (unless db-exists + (create-view-from-class 'bookmark) + (create-view-from-class 'tag) + (create-view-from-class 'bookmark-tag)))) + +(defun print-bookmark (bm) + "Print information about bookmark BM. + +BM should be a list containing the url and name of the bookmark." + (destructuring-bind (url name) bm + (format t "~A~%~A~%~%" url name))) + +(defun get-bookmarks () + "Get a list of all bookmarks. + +The result contains the url and the name of the bookmark." + (loop + with statement = (prepare-statement + *db* "select url, name from bookmark") + while (step-statement statement) + collect (list (statement-column-value statement 0) + (statement-column-value statement 1)) + finally (finalize-statement statement))) + +(defun clark () + (setf *db* (connect "test.db")) + (map nil #'print-bookmark (get-bookmarks)) + (disconnect *db*)) |