clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
em 2021-04-10T00:42:18.301800Z

@martinklepsch Here's a cute code-golf-y solution: (->> (range) (map #(quot % 3)) (partition 3 1) (map reverse) (take 10)) That said, while this is slightly more succinct, I much prefer @oscarlinusericsson’s version as it conveys the semantics of the intended operation much better.

👍 1
matheusashton 2021-04-10T02:02:05.303500Z

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

raspasov 2021-04-10T09:00:48.315400Z

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

steffan 2021-04-10T16:47:19.320100Z

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

matheusashton 2021-04-10T02:04:14.304Z

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

djblue 2021-04-10T02:28:39.304200Z

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

emccue 2021-04-10T02:53:34.304500Z

next.jdbc is the library to use with anything else

emccue 2021-04-10T02:53:49.304700Z

thats not an abstraction layer really, but still worth mentioning

seancorfield 2021-04-10T03:04:54.304900Z

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).

👍 1
💯 2
seancorfield 2021-04-10T03:05:53.305100Z

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

seancorfield 2021-04-10T03:06:59.305300Z

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

seancorfield 2021-04-10T03:07:55.305500Z

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

seancorfield 2021-04-10T03:08:40.305700Z

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

devn 2021-04-10T03:33:23.305900Z

what are the latest ORM-y situations in Clojure?

devn 2021-04-10T03:34:42.306100Z

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

devn 2021-04-10T03:35:48.306300Z

Toucan looks kind of neat

matheusashton 2021-04-10T03:51:38.306600Z

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

matheusashton 2021-04-10T03:52:22.306800Z

thanks for the suggestions 🙂

devn 2021-04-10T03:57:30.307Z

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

devn 2021-04-10T03:58:00.307200Z

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

seancorfield 2021-04-10T03:58:29.307500Z

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).

👍 3
devn 2021-04-10T04:00:54.307700Z

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

devn 2021-04-10T04:01:31.307900Z

toy projects or projects with long-term obviously limited scope

devn 2021-04-10T04:04:55.308100Z

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

devn 2021-04-10T04:05:51.308300Z

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.”

seancorfield 2021-04-10T04:08:59.308500Z

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 🙂

devn 2021-04-10T04:10:22.308700Z

yeah, it’s a fair point

devn 2021-04-10T04:11:07.308900Z

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

devn 2021-04-10T04:11:31.309300Z

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

seancorfield 2021-04-10T04:12:56.309500Z

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?).

seancorfield 2021-04-10T04:14:43.309700Z

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

devn 2021-04-10T04:15:16.309900Z

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

seancorfield 2021-04-10T04:16:38.310100Z

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

devn 2021-04-10T04:16:54.310300Z

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

devn 2021-04-10T04:17:31.310500Z

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

devn 2021-04-10T04:18:22.310700Z

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

devn 2021-04-10T04:19:24.310900Z

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

devn 2021-04-10T04:20:28.311100Z

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.

seancorfield 2021-04-10T04:20:42.311300Z

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.

seancorfield 2021-04-10T04:21:13.311500Z

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

devn 2021-04-10T04:21:29.311700Z

i still have a project using friend in prod

devn 2021-04-10T04:21:35.311900Z

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

devn 2021-04-10T04:22:09.312100Z

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”

devn 2021-04-10T04:23:17.312300Z

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

seancorfield 2021-04-10T04:24:34.312600Z

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

devn 2021-04-10T04:25:15.312800Z

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

devn 2021-04-10T04:26:11.313Z

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

devn 2021-04-10T04:27:01.313200Z

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

devn 2021-04-10T04:28:36.313400Z

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

devn 2021-04-10T04:28:45.313600Z

</rant>

1
2021-04-10T05:49:59.314200Z

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.

seancorfield 2021-04-10T06:57:30.314800Z

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

👍 1