Fork me on GitHub
#sql
<
2018-12-04
>
pablore19:12:00

Any jdbc-compatible in-memory databases out there? I was going to mock the Connection object in clojure for testing, but the amount of reifying was getting out of control.

seancorfield19:12:40

Yes, several are tested against as part of clojure.java.jdbc development.

seancorfield19:12:49

H2 can do in memory, for example.

seancorfield19:12:21

{:dbtype "h2:mem" ...} as I recall -- I'd have to go check the code / tests to be certain...

seancorfield19:12:52

See dependencies here that java.jdbc is tested against https://github.com/clojure/java.jdbc/blob/master/deps.edn

seancorfield19:12:56

H2 is one of them

seancorfield19:12:05

HSQLDB and Derby aren't "in-memory" but they are JVM-based and use local files so they might be suitable for testing against. Similarly SQLite. But the SQL dialect and column types each different DB supports will all be slightly different.

seancorfield19:12:58

You might also want to consider just wrapping tests in rollback transactions so you don't need to mock anything, but your tests' changes will automatically undo themselves.

seancorfield19:12:37

(and then of course there's always the advice to separate actual DB updates from data transformation as much as possible so you can test the transformations without even caring about a database)

seancorfield19:12:56

Hope some of that is helpful @pablore?

hiredman19:12:13

derby has in memory databases as well

seancorfield19:12:30

Not sure if java.jdbc has support for that with Derby. Feel free to create a JIRA ticket. But H2 in-memory is def. supported.

pablore19:12:53

Thanks @seancorfield! Rollback DBs are more difficult to setup on CI and the application I’m developing only reads the database and never wrties to it

1
pablore19:12:11

I’m gonna check out if H2 works for me

hiredman20:12:48

derby's in memory database seems to work fine (at least when passing a url as the connection spec)

johnj20:12:49

sqlite can be used in memory too

kulminaator20:12:34

these days people can also just spin up their actual database in a docker relatively quickly

kulminaator20:12:04

at my company that's the default solution for running db test suites in our buildserver

kulminaator20:12:23

just spinning up an empty postgres with a predefined username, throwing the schema and perhaps some initial data in, running the tests, throwing everything away after. works pretty well and we can easily have different versions of postgres around (and also test against new versions) rather easily.

👍 1