Fork me on GitHub
#sql
<
2019-10-16
>
tianshu01:10:18

@seancorfield Hi, is that next.jdbc will not recogize {:datasource ...} as a connection?

seancorfield03:10:50

@doglooksgood Did the documentation answer your question? And, if not, what would help make it clearer?

tianshu03:10:12

yeah, something confuse me. I've been using library conman for a while. this is a library to use with hugsql. conman provide a {:datasourcee DataSource} as connection. however recently I see conman has a commit say it support and switch to next.jdbc. but when using with next.jdbc, according to its example, it won't work. I can easily tweak the example code a little bit to make them work, but maybe I missed something?

tianshu03:10:04

according to the migration guide, I understand that next.jdbc narrow the options for db spec and it can now receive DataSource directly.

seancorfield03:10:34

I don't know anything about conman. The next.jdbc docs do explain how to use it with HugSQL tho' as it has a new next.jdbc adapter in HugSQL 0.5.1.

seancorfield03:10:54

next.jdbc also supports c3p0 and HikariCP for connection pooling out of the box.

seancorfield04:10:49

Ah, luminus-framework/conman? Version 0.8.4 says it has switched to next.jdbc but there don't seem to be any doc updates with it... It just seems to have changed dependencies?

seancorfield04:10:39

The examples in the readme are still using clojure.java.jdbc, not next.jdbc @doglooksgood -- you should open a GitHub issue on conman and ask them to update the readme!

tianshu04:10:07

yes, this is why I ask. I want to know if it is the situation that I should open an issue. I'll open a issue for that. conman is actually designed to be used for hugsql + mount. because mount don't do DI stuff, conman let you omit the db argument for sql function that generated by hugsql. anyway, I'll open a issue for this.

seancorfield04:10:01

I don't like dynamic globals. I don't like Mount. 🙂

tianshu04:10:55

there is already an issue.😂

tianshu04:10:26

I should found this ealier

seancorfield04:10:34

Ahah! There you go.

seancorfield04:10:18

Frankly, I wouldn't bother with conman. Not sure why Mount even needs it? (despite Mount's global state approach)

tianshu04:10:26

it's not necessary, but the function generated by hugsql need a db argument. that need to be passed by hand.

seancorfield04:10:38

Create a pooled datasource at startup -- using HikariCP and next.jdbc. Then just pass the datasource to HugSQL, per the next.jdbc docs.

seancorfield04:10:56

And in the mount stop lifecycle, just .close the pooled datasource.

tianshu04:10:24

yes, I could do that. but conman simply wrap the api of hugsql, so I can write code like this:

(conman/bind-connection system/*db-conn* "hugsql/user.sql")
(find-user)
also I can write a macro call with-transaction, bind tx connection to that dynamic var, so in the same thread, very convenient.

seancorfield04:10:51

It's bad practice, IMO.

seancorfield04:10:27

You can't easily write an app that uses multiple data sources. It makes testing harder. Global state is just horrible.

tianshu04:10:41

but If connection is injected into the handler, I will have to pass that to every place I will call a db function?

seancorfield04:10:22

Yes, you should pass it explicitly into the db functions.

seancorfield04:10:48

Global (mutable) state is a bad idea and should be avoided.

seancorfield04:10:13

Be explicit about the dependency on the DB (or other resources) and your code will be much easier to test.

tianshu04:10:42

I'm glad to hear about this

seancorfield04:10:06

We started over eight years ago with Clojure 1.3 alphas and we started with global state, like mount but home grown, because it was "easier" but it made for horrible maintenance down the road and we never do it now.

tianshu04:10:11

especially on how to test db function or how to test a part which contains a few db function calls.

seancorfield04:10:38

We have 90,000 lines of Clojure at work and we still have some legacy code depending on those global datasources and it's nasty to work with.

seancorfield04:10:03

We keep chipping away, rewriting it. And we regret that global state every day we touch that code!

tianshu04:10:35

I did not realize these maybe because my codebase is much smaller, it's just about 15k loc.

tianshu04:10:33

I also want to know what library you use to for scheduling jobs.

seancorfield04:10:55

Our apps work with four or five different datasources. In particular we have an optimized readonly datasource that can be configured to read from slaves, so it's very useful to be able to switch code from one to the other -- simply by passing the desired datasource in.

seancorfield04:10:12

Frankly, we use cron and run command line Clojure processes for that 🙂

seancorfield04:10:32

But we also have quite a few Clojure background processes that just run 24x7 and poll database tables.

tianshu04:10:12

so you don't use something like quartz?

seancorfield04:10:45

We don't need it.

seancorfield04:10:50

Simple things work.

tianshu04:10:54

how you reuse the db functions? will you put all stuffs in a single project, build with different profiles(source paths)?

seancorfield04:10:30

We have a monorepo with about 30 subprojects so we can build any combination of subprojects we want.

seancorfield04:10:37

All driven by CLI/`deps.edn`.

seancorfield04:10:27

We use depstar to build uber JAR files for automated deployment to production. We do not AOT compile anything.

tianshu04:10:28

I think I need re-thinking something

tianshu04:10:20

which library for system component management?

tianshu04:10:27

okay. thank you! these information help me a lot

seancorfield04:10:46

Happy to answer pretty much any questions you might have about how we do stuff.

seancorfield04:10:15

One day I might give a conference talk about it 🙂 or at least write more blog posts on http://corfield.org 🙂

tianshu04:10:39

let me know if you do

seancorfield17:10:23

Can folks RT this please to get a bit more visibility, so I can get a bit more feedback? https://twitter.com/seancorfield/status/1184292968758251520

👍 4