LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
285 stars 39 forks source link

Create views for often - used expressions #106

Open bendlas opened 12 years ago

bendlas commented 12 years ago

I'm thinking of a defview form, that gets a cql table, like

(defview customer-sales
  (-> (table :customer)
      (join (table :sales) (where (= :sales.customer :customer.id)))))

It creates a view customer_sales_view in the DB with the compiled sql and sets a :view "customer_sales_view" key on the cql table. If the view already exists, it checks whether the definition of the view equals the compiled sql.

When you use a table with a :view key in an expression, or deref directly, the compiler uses the precreated database view in the generated sql.

Pros

The first one is the biggie. I think it's best to punt the horrid issues of automatic schema upgrade, by refusing to automatically replace a view, if it's different to the one we want to intern. Yes, this means we need to compare two token streams in defview.


What do you think of it?

ghost commented 12 years ago

+1, it's a worthwhile idea