Fork me on GitHub
#beginners
<
2015-06-11
>
dilzio09:06:13

Hi group.. What is the analogue of an ORM in the Clojure/functional world…a layer for managing entities and relationships among entities? In java i’d use something like Hibernate which would allow me to lazy load child objects on demand but I’m not sure how you would model this in Clojure. Can I get some pointers?

matttylr10:06:04

I had the same question when starting to build a logistics application recently. Took a serious look at this project

matttylr10:06:10

However, I found using clojure.java.jdbc quite efficient and may app wasn't 'large enough' to warrant the extra complexity of an ORM-type approach

agile_geek10:06:40

@dilzio: other options are using DSL’s around relational database concepts e.g. http://sqlkorma.com/

matttylr10:06:17

SQL Korma is nice, very elegant

matttylr10:06:45

used it for a while but ended up dropping it for direct jdbc

matttylr10:06:32

if I had a simple map to insert/update as a row, that was v. straighforward with jdbc and if I had a more complex operation it is easier to express directly in sql

matttylr10:06:02

I know sql and don't want the extra bother of working out how to say something in sqlkorma dsl when I already know sql as a dsl!

agile_geek10:06:25

I think most people favour dealing with basic data structures like maps or possibly records and therefore don’t feel the need for an ORM style library.

matttylr10:06:26

However, I think @dilzio was after some record graph auto traversal properties

matttylr10:06:33

which I don't have a good answer for

matttylr10:06:57

My next stop is to look at datomic seriously

agile_geek10:06:20

@matttylr: no neither do I really. I suspect people hand craft traversal using map/reduce?

dilzio10:06:12

Thanks guys

dilzio10:06:03

so yeah what i’m looking for is to understand how i can model an object graph with a functional language

matttylr10:06:04

stewart sierra day of datomic talks give some info on that type of capability

matttylr10:06:45

@dilzio: are you constrained by keeping with a traditional RDBMS?

dilzio10:06:44

@mattlyr actually i will be using Cassandra

dilzio10:06:13

so i can model the data relationally if I want but i don’t have to

dilzio10:06:12

the key thing that i want to do be able to easily retrieve relationships. So for example… let’s say i have a data model with a many to one relationship of members to organization. in java/hibernate i’d do something like organization.getMembers() to retrieve it. I guess in clojure i’d need to do something like (getMembers orgid) ?

dilzio10:06:40

what I need however is to define declaratively the entity relationship in an edm file then have a framework that could read that

dilzio10:06:53

and do the mapping/retrieval for me

dilzio10:06:52

dunno if i’m really asking the right question vis a vis OO vs functional design

matttylr10:06:59

I wonder if that's the write approach with cassandra

matttylr10:06:24

I've not used it myself, but the guides talk about denormalisation and data duplication being encouraged

matttylr10:06:37

the idea of writing more data to make the reads more efficient

dilzio10:06:40

we use C* pretty extensively

dilzio10:06:53

that for me is an open question as well

agile_geek10:06:21

@dilzio: I’m a beginner too but whenever I catch myself modelling data in an OO paradigm I suspect I’m doing it wrong!

matttylr10:06:24

sort of the inverse of what you're used to with rdbms's

dilzio10:06:39

yeah i know what u mean

matttylr10:06:01

I've often found the same. If I ask 'how do I do this in clojure world', the answer is often 'you dont need to!'

dilzio10:06:31

one of the requirements is that i can specify my entities declaratively so i need the notion of entities… i do not however have to store them in a purely normalized canonical relational model

dilzio10:06:31

however in some cases it may make sense to do so…that’s part of what i’m trying to figure out as part of the whole ball of wax

matttylr10:06:36

but if you 'Model Around Your Queries' then really you're pushing that 'entity modelling' concern down to the database layer, leaving your clojure code to pull back data in the shape that you need it

matttylr10:06:01

just simple maps again

dilzio10:06:28

yeah, good point

dilzio10:06:43

so maybe just flatten everything out

matttylr10:06:43

I've also found the CQRS pattern useful in thinking about these things

matttylr10:06:07

ORM's worst aspect is that they enforce a symmetry in reads and writes

dilzio10:06:32

yeah agreed

matttylr10:06:50

the way you write data (especially in the case of systems like cassandra) is naturally different the way its retrieved

matttylr10:06:56

not always, but often

dilzio11:06:23

that’s a good point. Maybe this is less of a clojure question and more of a pure modeling question (insert lightbulb emoji here)

dilzio11:06:10

haha thanks…couldn’t track it down simple_smile

dmich11:06:22

I gotta say, Clojure #C053AK3F9 seem to ask pretty advanced questions 😛

escherize11:06:59

Clojure has some high level beginners for sure

agile_geek11:06:06

Maybe we need an intermediates channel? 😉

agile_geek11:06:22

Oh joy, more channels to monitor!

dmich11:06:28

I stopped visiting the IRC #C03S1KBA2 channel because is was just too busy. Very hard to follow.

escherize11:06:19

yea man, who wants to monitor just 1 channel?

agile_geek11:06:24

I’m currently reading the beta version of https://pragprog.com/book/vmclojeco/clojure-applied to get a steer on issues like when to use records vs maps, etc. (plug for @alexmiller)

dmich11:06:06

out November? 😞

agile_geek11:06:08

@dmich: well you can buy the beta version now. We could ask @alexmiller if he thinks he’s on target for a mid November publishing date.

alexmiller12:06:21

Clojure Applied should be out in August - it's in final tech review now

alexmiller12:06:32

The current beta has all but one chapter

agile_geek12:06:40

@alexmiller: Thanks Alex. I’m enjoying the first chapter so far. I’ll let you have any comments/questions but so far all is good. simple_smile

alexmiller12:06:01

Thanks! If you do find issues, please file them in the errata page at the prag site - we track them there and you can see when it's fixed etc

andrewvida14:06:19

Anyone using Atom editor (http://atom.io) for clojure development?

akiva14:06:03

@andrewvida: There’s an #C050AN6QW channel. Might get more traction there.

andrewvida14:06:37

great! Thanks @akiva! I’ll ask in there.

yusup17:06:06

Hi, what do recommend for logging in Clojure ?

yusup17:06:23

Libraries I mean.

sveri17:06:52

Looks interesting

yusup17:06:54

how to achieve thread safety? agent ?

sveri17:06:46

For which problem?

yusup17:06:07

@sveri: for logging. I have many worker threads , each prints job status.

sveri17:06:55

Sorry, i don't know. Never looked after that. Maybe read the instructions or ask the maintainer?

sveri17:06:16

Or someone else here knows

yusup17:06:45

ok thanks

barton20:06:11

A very mutable question, but what would you use for a simple CRUD web app in Clojure / how would you structure the back-end?

seancorfield20:06:27

@markstang: I find it cleaner to use :dbtype / :dbname most times: `

seancorfield21:06:19

(def db {:dbtype "postgres" :dbname "CybershopDB_2" :user "postgres" :password "postgres" :port 5432})

barton21:06:20

I’m convincing myself that I need to use korma, maybe to do some creative macro stuff one day to customize the SQL queries, since it’s easier with a s-exp… 😃

seancorfield21:06:51

Take a look at HoneySQL if you want composable queries-as-sexps

seancorfield21:06:00

(linked from java.jdbc docs)

barton21:06:22

honeysuckle, hur hur 😃

barton21:06:37

Looks great, thanks!

seancorfield21:06:47

I should default 5432 for PostgreSQL really in java.jdbc...

seancorfield21:06:24

We use HoneySQL extensively for complex reporting queries at World Singles. My colleague gave a talk on it at Clojure/West.

sveri21:06:42

@barton: I build a very basic crud plugin: https://github.com/sveri/closp-crud using korma and selmer, it's part of closp: https://github.com/sveri/closp

aaronm21:06:02

@seancorfield: I watched that talk, looked interesting, though I haven’t had an opportunity to try it out yet.

donaldball21:06:17

I quite like honeysql as well

donaldball21:06:15

It's a very good 90% solution and has proven easy to modify. Its biggest lack is coherent documentation, honestly.

seancorfield21:06:56

@donaldball: That’s a valid criticism for a lot of Clojure libraries I’m afraid. I find I spend a lot of time reading source code for many of the libraries I use.

aaronm21:06:17

sadly, libraries in most languages

seancorfield21:06:35

True dat. We developers are — in general — not awfully good at documentation 😞

donaldball21:06:50

It's almost as if technical writing and software development were distinct disciplines

sveri22:06:57

@seancorfield: @donaldball therefore, I find it easiest to understand clojure code, compared to other languages, it's almost as reading docs

barton23:06:06

@sveri: closp-crud is perfect for what I currently need, thank you! Any relation to Unaha-Closp? 😃