Live data from Hacker News

ClojureQL - 1.0.0 now in beta

bestinclass.dk

11–20 of 23 posts

Re: ClojureQL - 1.0.0 now in beta

#11

I can not understand what problem this library solves ? Why to write SQL in Clojure and translate it back to SQL ? Examples on website are quite simplistic. They are far away from real life SQL queries that usually bigger and more complex (not select and join couple of tables). What about "group by", joining 5 or 8 tables etc.? How you are supposed to prototype and test your queries on existing schema (there are many…

Clojure code is Clojure data. So, these SQL statements are really just nested lists. Instead of writing an ad-hoc SQL parser and doing string manipulation, you can write relatively simple Clojure functions to manipulate these lists and generate valid SQL.

1. Why to write an ad-hoc sql parser in Clojure. The result of query is a JDBC ResultSet (on JVM). You may define some functions that transform rows from ResultSet to Clojure terms in order to make your code shorter.

2. They are not simple functions. Compare this : (-> (select (table {} {:employees :p})(where (= :name "John")))(join (table {} {:employees :b})(where (= :p.manager :b.id)))to-sql)

to this :

SELECT p.,b. FROM employees p JOIN employees b ON (p.manager = b.id) WHERE (name = 'John')

Which one is more verbose ?

EDIT: SQL examples with "employees" and "departmets" are very misleading and usually oversimplify the reality.

Re: ClojureQL - 1.0.0 now in beta

#12

I can not understand what problem this library solves ? Why to write SQL in Clojure and translate it back to SQL ? Examples on website are quite simplistic. They are far away from real life SQL queries that usually bigger and more complex (not select and join couple of tables). What about "group by", joining 5 or 8 tables etc.? How you are supposed to prototype and test your queries on existing schema (there are many…

ClojureQL forms are composable abstractions. One can let a clojureql query, execute it, do x with the results, add a where clause and get back another set of results-- all without any code repetition.

Re: ClojureQL - 1.0.0 now in beta

#13

Earlier quoted context omitted.

Clojure code is Clojure data. So, these SQL statements are really just nested lists. Instead of writing an ad-hoc SQL parser and doing string manipulation, you can write relatively simple Clojure functions to manipulate these lists and generate valid SQL.

1. Why to write an ad-hoc sql parser in Clojure. The result of query is a JDBC ResultSet (on JVM). You may define some functions that transform rows from ResultSet to Clojure terms in order to make your code shorter. 2. They are not simple functions. Compare this : (-> (select (table {} {:employees :p})(where (= :name "John")))(join (table {} {:employees :b})(where (= :p.manager :b.id)))to-sql) to this : SELECT p. ,b…

But your missing the point. You can store parts of queries and reuse them, recombine them however you see fit:

  (def users (cql/table db :users))
  (def photos (cql/table db :photos))

  (def users-and-photos
     (cql/join users photos
               (cql/where (= :users.id :photos.user_id))))
  
  (def photo-titles
     (-> users-and-photos
         (cql/project #{:photos.title})))
Note that my queries just keep getting smaller and smaller ;) By writing the mundane portions of your SQL queries again and again by hand you will have more duplication.

Re: ClojureQL - 1.0.0 now in beta

#14

Earlier quoted context omitted.

Clojure code is Clojure data. So, these SQL statements are really just nested lists. Instead of writing an ad-hoc SQL parser and doing string manipulation, you can write relatively simple Clojure functions to manipulate these lists and generate valid SQL.

1. Why to write an ad-hoc sql parser in Clojure. The result of query is a JDBC ResultSet (on JVM). You may define some functions that transform rows from ResultSet to Clojure terms in order to make your code shorter. 2. They are not simple functions. Compare this : (-> (select (table {} {:employees :p})(where (= :name "John")))(join (table {} {:employees :b})(where (= :p.manager :b.id)))to-sql) to this : SELECT p. ,b…

if the point is length of code, then:

  SELECT p.*,b.* FROM employees p JOIN employees b ON (p.manager = b.id) WHERE (p.name = 'John')
is only 8 characters less than:

  (join (select (table {:employees :p}) (=* :name "John")) (table {:employees :b}) (=* :p.manager :b.id))
but that isn't the point. the point is composabilty. you can take 8 simple functions (select, project, join, rename, aggregate, take, drop, sort) and build any query you want. these queries can be passed around your code, reused, modified, and refined, in a way that plain SQL strings cannot.

Re: ClojureQL - 1.0.0 now in beta

#15

Earlier quoted context omitted.

I read the article. The guy claims that SQL is hard -- yes it is hard for real life cases and there are limitations imposed by underlying theory (relational algebra). Joining the table with itself may be little mind-blowing when you do it first time. It still does not mean that we need to write queries in different language and translate them back to SQL. A simple question is "how the hell you use prepared statements…

I suggest you read this article, http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...

I am not against new ways of querying RDBMSes but until today SQL seems the most simplest and clean way to do it. Most realistic solution will be not to abstract SQL but develop a new query language for relational datasources (on same level with SQL). I am pro abstractions that simplify things (like TCP) and against naive abstractions ignoring the basic aims of layers under. TCP simplifies things, Clojure-QL complicates them.

PS: The article that you suggested is written by a guy that tend to speculate over his point of view without taking in account the reality. In all modern RDBMSes queries having (a=b and a=c and b=c) will be simplified by query planners (Oracle and Postrgre do it) so there will not be any difference in performance.

Re: ClojureQL - 1.0.0 now in beta

#16

Earlier quoted context omitted.

1. Why to write an ad-hoc sql parser in Clojure. The result of query is a JDBC ResultSet (on JVM). You may define some functions that transform rows from ResultSet to Clojure terms in order to make your code shorter. 2. They are not simple functions. Compare this : (-> (select (table {} {:employees :p})(where (= :name "John")))(join (table {} {:employees :b})(where (= :p.manager :b.id)))to-sql) to this : SELECT p. ,b…

But your missing the point. You can store parts of queries and reuse them, recombine them however you see fit: (def users (cql/table db :users)) (def photos (cql/table db :photos)) (def users-and-photos (cql/join users photos (cql/where (= :users.id :photos.user_id)))) (def photo-titles (-> users-and-photos (cql/project #{:photos.title}))) Note that my queries just keep getting smaller and smaller ;) By writing the m…

Yes I agree. But, I believe that it is just a perversion. In any project that involves RDBMS writing queries is just a small part of development. Surely you could modify queries with Clojure-QL (with SQL it will be a suicide) but what you gain from it ??? (more free time - I don't think so). Furthermore, having such dynamic "meta-"things in your code, eventually will cost you more time in debugging it.

With SQL it is straight-forward: you prototype your query using some GUI client and then you just embed it in your program. How it can be done with Clojure-QL ?

Re: ClojureQL - 1.0.0 now in beta

#17

I can not understand what problem this library solves ? Why to write SQL in Clojure and translate it back to SQL ? Examples on website are quite simplistic. They are far away from real life SQL queries that usually bigger and more complex (not select and join couple of tables). What about "group by", joining 5 or 8 tables etc.? How you are supposed to prototype and test your queries on existing schema (there are many…

I suggest watching the screencast. It has examples of some pretty complex queries including aggregating and group by.

Re: ClojureQL - 1.0.0 now in beta

#19

Earlier quoted context omitted.

I read the article. The guy claims that SQL is hard -- yes it is hard for real life cases and there are limitations imposed by underlying theory (relational algebra). Joining the table with itself may be little mind-blowing when you do it first time. It still does not mean that we need to write queries in different language and translate them back to SQL. A simple question is "how the hell you use prepared statements…

I suggest you read this article, http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...

Idea: Bot which automatically gives relevant replies to comments, using NLP, sentiment analysis and web search to find relevant links. It would only reply if it's certain enough that the link it wants to suggest is relevant enough and has a dissenting opinion relative to the comment as well as decent pagerank/social-media-rank.
Post reply on HN