Skip to content

Commit

Permalink
WIP - Explore basic sqlite interaction via next.jdbc
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan committed Oct 12, 2024
1 parent 97e4e36 commit 6db98cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{:deps
;; Clojure standard library
{org.clojure/clojure {:mvn/version "1.11.0"}
org.clojure/core.async {:mvn/version "1.6.681"}
org.clojure/data.csv {:mvn/version "1.0.1"}} ;; NOTE: For testing CSV input/output only..
{org.clojure/clojure {:mvn/version "1.11.0"}
org.clojure/core.async {:mvn/version "1.6.681"}
com.github.seancorfield/next.jdbc {:mvn/version "1.3.955"}
org.xerial/sqlite-jdbc {:mvn/version "3.46.1.3"}
org.clojure/data.csv {:mvn/version "1.0.1"}} ;; NOTE: For testing CSV input/output only..
:aliases
{:repl/basic
{:extra-deps {nrepl/nrepl {:mvn/version "1.0.0"}
Expand Down
22 changes: 22 additions & 0 deletions src/swark/cedric.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,25 @@
(transact! archive-items {:primary-key :user/id} [{:user/id "4"}])
;; Close the connection via the close! function
(close!))

(comment
;; JDBC
(require '[next.jdbc :as jdbc])
(let [db {:dbtype "sqlite" :dbname "example"}
ds (jdbc/get-datasource db)
tx (utc-now)
ea :user/id
ev "c"
a :user/name
v "Arnold"]

;; Step one. Create table for storing EAV lines.
#_(jdbc/execute! ds ["CREATE TABLE lines (id int auto_increment primary key, tx timestamp, entity_attribute varchar(32), entity_value varchar(32), attribute varchar(32), value varchar(255))"])

;; Step two. How to insert a row
#_(jdbc/execute! db ["insert into lines(tx, entity_attribute, entity_value, attribute, value) values (?, ?, ?, ?, ?)" tx ea ev a v])

;; Step Three. Reading.
(jdbc/execute! db ["select * from lines"])
))

0 comments on commit 6db98cf

Please sign in to comment.