https://github.com/fukamachi/cl-dbi.git
git clone 'https://github.com/fukamachi/cl-dbi.git'
(ql:quickload :cl-dbi)
(defvar *connection*
(dbi:connect :mysql
:database-name "test"
:username "nobody"
:password "1234"))
(let* ((query (dbi:prepare *connection*
"SELECT * FROM somewhere WHERE flag = ? OR updated_at > ?"))
(result (dbi:execute query 0 "2011-11-01")))
(loop for row = (dbi:fetch result)
while row
;; process "row".
))
dbi:with-connection
to ensure connections are closed(dbi:with-connection (conn :sqlite3 :database-name "/home/fukamachi/test.db")
(let* ((query (dbi:prepare conn "SELECT * FROM People"))
(result (dbi:execute query)))
(loop for row = (dbi:fetch result)
while row
do (format t "~A~%" row))))
CL-DBI provides the same interface for multiple SQL databases. You need not learn the API of each database.
This library is especially convenient when you want to use different databases in different environments. For example, you may use MySQL as a production database, but use SQLite3 on your development system. To switch database backends you need only change the arguments to dbi:connect
.
This library will be available on Quicklisp when ready for use.
Create a subclass of <dbi-driver> and implement following methods.
These methods can be overriden if needed.
Copyright (c) 2011 Eitaro Fukamachi (e.arrows@gmail.com)
Licensed under the LLGPL License.