如何使用 cl-dbi 连接到 SQlite
How to connect to SQlite using cl-dbi
尝试过:
(defvar connection
(dbi:connect :mysql
:database-name "test"
:username "nobody"
:password "1234"))
结果:
System "dbd-sqlite" not found
[Condition of type QUICKLISP-CLIENT:SYSTEM-NOT-FOUND]
任何人都可以指出在 Sqlite3 中使用 cl-dbi 的示例吗?
(cl-dbi:connect :sqlite3 :database-name "db.db")
使用:sqlite3
作为驱动程序名称。
您在 README 中有一个线索:https://github.com/fukamachi/cl-dbi#using-dbiwith-connection-to-ensure-connections-are-closed(相应地,它可能更明确)
(dbi:with-connection (conn :sqlite3 :database-name "/home/fukamachi/test.db")
;; ^^^ sqlite3
(let* ((query (dbi:prepare conn "SELECT * FROM People"))
(query (dbi:execute query)))
(loop for row = (dbi:fetch query)
while row
do (format t "~A~%" row))))
还有此处文档的指针:https://lispcookbook.github.io/cl-cookbook/databases.html#connecting-to-a-db(Mito ORM 使用 cl-dbi)。
玩得开心!
尝试过:
(defvar connection (dbi:connect :mysql :database-name "test" :username "nobody" :password "1234"))
结果:
System "dbd-sqlite" not found
[Condition of type QUICKLISP-CLIENT:SYSTEM-NOT-FOUND]
任何人都可以指出在 Sqlite3 中使用 cl-dbi 的示例吗?
(cl-dbi:connect :sqlite3 :database-name "db.db")
使用:sqlite3
作为驱动程序名称。
您在 README 中有一个线索:https://github.com/fukamachi/cl-dbi#using-dbiwith-connection-to-ensure-connections-are-closed(相应地,它可能更明确)
(dbi:with-connection (conn :sqlite3 :database-name "/home/fukamachi/test.db")
;; ^^^ sqlite3
(let* ((query (dbi:prepare conn "SELECT * FROM People"))
(query (dbi:execute query)))
(loop for row = (dbi:fetch query)
while row
do (format t "~A~%" row))))
还有此处文档的指针:https://lispcookbook.github.io/cl-cookbook/databases.html#connecting-to-a-db(Mito ORM 使用 cl-dbi)。
玩得开心!