Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using clojure's korma sqlite3 helpers, what's the default path for the sqlite3 database?

When using korma.db, defdb can take a sqlite3 helper to establish a connexion to a sqlite3 database. However, I've tried placing the database on the root of the project directory, alongside project.clj, and on the resources directory, but when I try to use the db I get:

Failure to execute query with SQL: SELECT "examples".* FROM "examples" :: [] SQLException: Message: [SQLITE_ERROR] SQL error or missing database (no such table: examples)

Needless to say my sqlite database contains an examples table. When trying to do this, I get a sqlite.db file of zero bytes placed on the root project dir.

I'm doing this from lein repl within the project, by the way.

Edit: This is what I do when it fails:

(use 'korma.db)
(defdb db (sqlite3 {:db "filename.db"}))
(use 'korma.core)
(defentity examples)
(select examples)
like image 613
user3112185 Avatar asked Nov 11 '22 16:11

user3112185


1 Answers

Just in case anybody is wondering or runs into this...

Using version [korma "0.4.2"] and [org.xerial/sqlite-jdbc "3.7.15-M1"] in my project.clj:

My project structure looks like:

root/project.clj
root/db/dev.sqlite3
root/src/...

and this is how I use korma to access the db:

(use 'korma.db)
(defdb mydb {:classname "org.sqlite.JDBC"
      :subprotocol "sqlite"
      :subname "db/dev.sqlite3"})

Basically, using subname, I'm able to search in the root of the lein project. I added db/ in the subname per my dir structure above.

like image 200
teh0xqb Avatar answered Nov 15 '22 05:11

teh0xqb