Fork me on GitHub
#sql
<
2017-06-13
>
pandeiro13:06:19

I'm using the 42.x.y releases and no issues at all

psalaberria00216:06:22

is there any clojure sql library that handles many to many relational tables? I am trying with honeysql, but it feels like I have to do a lot of manual work for inserts and selects.

psalaberria00216:06:25

let's say I have users and products.

psalaberria00216:06:42

and the query I want is select a specific user. Ideally the user object will contain a list of products

tanzoniteblack17:06:23

@psalaberria002 if you want to manage the SQL queries yourself, then normal level of work involving joins is going to happen. If you want an ORM like thing, you can use http://sqlkorma.com/

tanzoniteblack17:06:52

personally, I prefer to have raw control of the resulting SQL queries using https://github.com/jkk/honeysql

psalaberria00217:06:15

I was probably just being lazy 😉 I will give it a try to Korma, and if it doesn’t fit the purpose I will get back to raw honeysql. thank you @tanzoniteblack

tanzoniteblack17:06:32

I’ve used yesql, honeysql, and korma in production projects, and have generally found that korma allows you to get code out the door very fast…but over time it becomes more difficult to maintain for high performance then just doing it with the raw SQL to begin with

tanzoniteblack17:06:26

so then the korma codebase became a mishmash of korma slowly being replaced by either raw SQL strings, yesql, or honeysql (depending on the point in time and which project we were working on)

shaun-mahood22:06:30

Are there any specific reasons to avoid putting raw SQL into Clojure strings and executing them using jdbc for the parameters? Performance and security are probably the ones I'm most curious about. I've got a whole bunch of opinions on things like this built up over years of reading and working with different languages and libraries, so it can be tough to know what in my brain is still accurate given modern tooling and programming practices.

tanzoniteblack22:06:54

@shaun-mahood the only reasons that you often don’t want to do that are: 1.) Escaping \” can be annoying 2.) Clojure isn’t great at formatting / syntax highlighting SQL, which makes it easier to introduce bugs 3.) You can’t compose queries without a lot of string hackery

tanzoniteblack22:06:34

the other reason is that if you have a lot of ? variables, it’s easy to pass them in in the wrong order on accident

tanzoniteblack22:06:24

you might try out https://github.com/jkk/honeysql instead; it’s a thin wrapper to generate raw SQL queries from Clojure data structures that avoids most of the problems I just mentioned and still allows you to directly use JDBC https://github.com/krisajenkins/yesql / https://www.hugsql.org/ are other options that allow you to convert semi-special .sql files into clojure functions

hiredman22:06:26

I had an open issue on yesql once,then they disabled issues on their repo

tanzoniteblack22:06:24

I like the theory of yesql and hugsql (raw special parameterized SQL converted to clojure functions), but in practice I’ve never actually been happy with either.

tanzoniteblack22:06:27

Honeysql I like a lot though

shaun-mahood22:06:48

@tanzoniteblack: Thanks - I've used honeysql, yesql, and hugsql in the past as well. I like honeysql quite a lot for composition, but a lot of my sql work doesn't really make sense for that.

tanzoniteblack22:06:25

yeah; if you’re not dynamically composing SQL, then there’s nothing wrong with parameterized strings passed into JDBC

shaun-mahood22:06:57

@hiredman: I think yesql is actively looking for a maintainer now, I'm kind of hoping it consolidates with hugsql

shaun-mahood22:06:07

I'm in the same place with both yesql and hugsql - seems like extra dependencies for little benefit (on a team of 1 and building across the full stack though - I think they would be fantastic if you had dedicated db admins)