From 15009cb946f9cea49e697b2f3f7ab5df2213ab38 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 9 Dec 2018 17:36:45 -0500 Subject: [PATCH] Add SQLite info from README. --- SQLite.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SQLite.md diff --git a/SQLite.md b/SQLite.md new file mode 100644 index 0000000..00b6835 --- /dev/null +++ b/SQLite.md @@ -0,0 +1,31 @@ +# SQLite bindings + +There are some sqlite3 bindings in the directory natives/sqlite3 bundled with +the janet source code. They serve mostly as a +proof of concept external c library. To use, first compile the module with Make. + +```sh +make natives +``` + +Next, enter the repl and create a database and a table. + +``` +janet:1:> (import natives/sqlite3 :as sql) +nil +janet:2:> (def db (sql/open "test.db")) + +janet:3:> (sql/eval db `CREATE TABLE customers(id INTEGER PRIMARY KEY, name TEXT);`) +@[] +janet:4:> (sql/eval db `INSERT INTO customers VALUES(:id, :name);` {:name "John" :id 12345}) +@[] +janet:5:> (sql/eval db `SELECT * FROM customers;`) +@[{"id" 12345 "name" "John"}] +``` + +Finally, close the database connection when done with it. + +``` +janet:6:> (sql/close db) +nil +```