Janet Notes and Examples

Databases

Install the sqlite package:

jpm install sqlite3

That will pull in and build its own sqlite. However, if you want to have it use the system sqlite3:

export JANET_SYSTEM_SQLITE=1
jpm install sqlite3

Use:

(import sqlite3 :as sql)

(def db (sql/open "foo.db"))

(sql/eval db
  `insert into names (fname, lname, date) values (:fname, :lname, :date);`
  {:fname "Bert" :lname "Beet" :date (os/time)})


(let [a (sql/eval db `select * from names;`)]
  # Returns an array.
  # Each element in the array is a struct.
  (each e a
    (pp e)))

(sql/close db)