Fork me on GitHub
#clojure
<
2021-04-10
>
matheusashton02:04:05

Hello, I'm starting a new project in clojure and I wanted some suggestions of good libraries for sql abstraction

matheusashton02:04:14

I liked Korma, but it looks like unmaintained for a long time

djblue02:04:39

I think https://github.com/seancorfield/honeysql is a pretty good way to write sql from clojure

emccue02:04:34

next.jdbc is the library to use with anything else

emccue02:04:49

thats not an abstraction layer really, but still worth mentioning

seancorfield03:04:54

I'm biased but I recommend next.jdbc + HoneySQL if you want programmatically composable SQL statements. If you prefer to write SQL and keep it in separate files to your Clojure code, look at HugSQL (and next.jdbc for the JDBC integration).

💯 6
👍 3
seancorfield03:04:53

ORM-style stuff really isn't idiomatic in Cloure (Korma, Toucan).

seancorfield03:04:59

An interesting alternative is Walkable, where you'll get EQL (a sort of Datalog-style query language) that maps down to SQL.

seancorfield03:04:55

(we use next.jdbc + HoneySQL very heavily in production at work)

seancorfield03:04:40

@U8C850K42 Feel free to drop into the #sql channel to discuss in more depth. There's also #honeysql #hugsql #walkable

devn03:04:23

what are the latest ORM-y situations in Clojure?

devn03:04:42

still Korma? I guess you mentioned Toucan, not familiar with it

devn03:04:48

Toucan looks kind of neat

matheusashton03:04:38

I saw hug sql and didn't like it, it remembered old ibatis in java and I missed composition that I've found in korma, I'll try next + honey

matheusashton03:04:22

thanks for the suggestions 🙂

devn03:04:30

fwiw, i’ve played the korma game and i won, but it was a small personal project

devn03:04:00

i recognize everyone has their own feelings about ORMs and what-not, but I don’t mind reaching for one for really well-scoped projects

seancorfield03:04:29

I've worked with a lot of ORM-style libraries in several different techs and I hate them all 🙂 I've even written a couple of ORMs (and I hate those too).

👍 9
devn04:04:54

i don’t hate the ones that have made me wildly productive when all i needed were basic operations

devn04:04:31

toy projects or projects with long-term obviously limited scope

devn04:04:55

i’ve been bitten, but i definitely can’t say all of them were bad experiences

devn04:04:51

most, probably, but not all. i just learned to dial in when i would say “fine, let’s use one. doesn’t matter for this app either way.”

seancorfield04:04:59

It's true that they can be OK for very simple CRUD stuff and in most languages they are easier than rolling your own. I haven't ever felt that in Clojure tho'. (sql/insert! ds :table map-of-data) and (sql/get-by-id ds :table pk) are about as simple as you can get for basic CRUD 🙂

devn04:04:22

yeah, it’s a fair point

devn04:04:07

im just saying i don’t hate the idea of some well-maintained “balance of ease > simplicity” option existing in the ecosystem

devn04:04:31

because depending on the project i could see myself reaching for it

seancorfield04:04:56

It's been interesting maintaining clojure.java.jdbc and now next.jdbc for nearly a decade, and HoneySQL for the last few years (can't quite remember when I took that over?).

seancorfield04:04:43

Hmm, mid-2018. So it's been nearly three years.

devn04:04:16

one common case i can’t ignore: Rails’ Devise is so incredibly easy for auth

seancorfield04:04:38

Yeah, auth is an area that Clojure has always been lacking...

devn04:04:54

i cringe a bit when all i want to do is get some basic thing working with “a user logs in” and it’s like a day-long effort

devn04:04:31

again, accounting for the fact that the thing i’m working on /doesn’t need custom auth/ and won’t ever

devn04:04:22

err i can’t say that definitively, but pretend i am building an app i control 100% for the sake of argument

devn04:04:24

i would kill for a better auth story, but good auth stories wind up being good because there’s some kind of model-based thing going on, a framework is in play, whatever

devn04:04:28

at least that’s my experience… i think aaron bedra basically said this about clojure security awhile back. libraries over frameworks is great until you want to reason about some kind of unified security model.

seancorfield04:04:42

At work, it didn't matter because we decided to write our own identity server and do oauth2 from scratch -- and that's an area that is so poorly documented! We ended up building it all on top of Apache OLTP and Jose JWT.

seancorfield04:04:13

(and we support FB OAuth2 too -- but client-side stuff is pretty easy)

devn04:04:29

i still have a project using friend in prod

devn04:04:35

i don’t really want to talk about that code tho, tbqh

devn04:04:09

i’ve implemented things from the bits and pieces of buddy. some of those were really great experiences, and a couple were like “why am i doing this”

devn04:04:17

or messing with bouncycastle and starting to worry about holding onto the wrong thing in memory or not having the right hint in the right place

seancorfield04:04:34

Yeah, I've looked at both Friend and Buddy and they seem... really fiddly... to work with... lots of moving parts...

devn04:04:15

all of this is to say that while i understand the philosophy because i’ve been living in it for 10+ years at this point, i’m happy to accept some stupid ORM CRUD thing every once and again and I won’t feel the least bit bad about it

devn04:04:11

“consenting adults language” and all that is a phrase worth remembering

devn04:04:01

i reserve the right to do things “wrong” in the same way i can create and bash on an array of int in clojure instead of using a persistent vector

devn04:04:36

preference is one thing, but I am happy to make the occasional tradeoff, depending

devn04:04:45

</rant>

3
jmayaalv05:04:59

If you are using Postgres you should check https://github.com/kwrooijen/gungnir it has an orm like feel and it's easy to get started.

seancorfield06:04:30

Note that Gungnir only works with HoneySQL V1; I’m in talks with the maintainer about how to make this work with HoneySQL V2.

👍 3
raspasov09:04:48

Walkable looks really interesting; that’s I think what I’ve been looking for from a SQL database for a long time;

steffan16:04:19

Another PostgreSQL specific library providing an SQL abstraction : https://github.com/retro/penkala