This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-15
Channels
- # babashka (12)
- # beginners (88)
- # calva (6)
- # cider (4)
- # clerk (110)
- # clojure (18)
- # clojure-czech (1)
- # clojure-europe (26)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-poland (8)
- # clojure-spain (2)
- # clojure-uk (2)
- # clojurescript (22)
- # cursive (11)
- # data-science (1)
- # datalevin (5)
- # datomic (35)
- # events (1)
- # fulcro (2)
- # gratitude (5)
- # helix (4)
- # hoplon (20)
- # hyperfiddle (52)
- # jobs (3)
- # lsp (1)
- # malli (48)
- # missionary (11)
- # off-topic (31)
- # practicalli (1)
- # reitit (7)
- # releases (1)
- # remote-jobs (7)
- # scittle (9)
- # shadow-cljs (7)
- # sql (11)
- # xtdb (5)
Folks, somebody that uses next.jdbc
- how do I use an in-memory database? I made the datasource like this:
(def ds (jdbc/get-datasource {:dbtype "sqlite"
:dbname ":memory:"}))
But it seems that after each command, database is disconnected, meaning that the whole DB is erased... I can't even run a CREATE TABLE
and select it after...Ok, nevermind - seems that I want get-connection
.
That must be something peculiar to SQLite because the H2 in-memory DB is used throughout the next.jdbc
tests and it doesn't vanish between operations...?
Yes, H2 have this behavior - you can have multiple "in-memory" databases with specific names. I remember I had the opposite "problem" on H2 (I was expecting to work as SQLite works, and the tables were persisting between connections)
Ah, interesting.
(actually, now that you mention, maybe H2 is actually better for my use-case :rolling_on_the_floor_laughing:)
For SQLite, the database lives in a single connection only. Once you've closed it, the db is gone. So you spawn a connection using get-connection
and pass it everywhere.
The same applies to a file-driven sqlite: without get-connection, you'll be opening and closing the file on each query. So you need a persistent connection.
@U1WAUKQ3E You could use a connection pool like HikariCP with SQLite for file-based access, right? The same is true of all DBs: if you pass a spec hash map or even a plain datasource around, it'll create a new connection for every operation which is very wasteful/slow.
I haven't tried HikariCP with SQLite yet as it might lead to weird behaviour, I believe. Although the pool reuses the connections, there is still a chance that you get a new connection with a new in-memory db.
I want suggesting for in memory, only for file based