I'd prefer to combine #1 with a validation layer, similar to prismatic's schema but with a few tweaks. Something* that filtered the param keys based on the allowed columns and ensured the values were sane. Then, hopefully write generic sql helper fns to create the parameterized SET stmt string: "id=?, name=?, price=?" without needing to explicitly destructure them.
Lots of good discussion on keyword args: https://groups.google.com/forum/#!searchin/clojure/keyword$20parameters%7Csort:date/clojure/yzLCZh-GiQ8/hypLf32IsigJ *I'll publish that lib as soon as priorities allow it. On Monday, May 19, 2014 12:07:15 PM UTC-5, Ivan Schuetz wrote: > > Hi, > > I'm building a webservice, have 2 layers: webservice and database. > > Webservice layer receives e.g. a product, to add to the database: > > {:id 1 :name "phone" :price 100} > > Database layer has a method to insert the product, insert-product. > > I could do 1): > > (defn insert-product [params]) > > or 2): > > (defn insert-product [id name price]) > > or 3): > > (defn insert-product [{:keys [id name price]}) > > > I tend to prefer 2) because it's safer than 1) and will allow me to add > type check later, don't think this is possible with 3). It doesn't feel > very idiomatic though and makes me feel like I might be "thinking in > Java"... > > > I also want make possible to change the keys before inserting in the > database, where 2) and 3) are better than 1). > > > Is 2) the best option? Is there any reason to use 3) instead? Or is there > maybe a different, better way? > > > > Thanks! > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
