Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save josephwinston/418bf260444e85e51990419097c1c29f to your computer and use it in GitHub Desktop.
Save josephwinston/418bf260444e85e51990419097c1c29f to your computer and use it in GitHub Desktop.
Calling pglight from nbb/clojurescrip
(ns example
(:require [applied-science.js-interop :as j]
[promesa.core :as p]
["@electric-sql/pglite" :as PGlite]))
(p/let [db (new PGlite.PGlite)
_ (j/call db :exec "CREATE TABLE IF NOT EXISTS todo (id SERIAL PRIMARY KEY, task TEXT, done BOOLEAN DEFAULT fals
e);")
_ (j/call db :exec "INSERT INTO todo (task, done) VALUES ('Install PGlite from NPM', true);")
_ (j/call db :exec "INSERT INTO todo (task, done) VALUES ('Load PGlite', true);")
_ (j/call db :exec "INSERT INTO todo (task, done) VALUES ('Create a table', true);")
_ (j/call db :exec "INSERT INTO todo (task, done) VALUES ('Insert some data', true);")
_ (j/call db :exec "INSERT INTO todo (task) VALUES ('Update a task');")
result (j/call db :query "SELECT * FROM todo;")
]
(js/console.log result)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment