On Tue, Oct 2, 2012 at 6:54 AM, Jeremy Evans <[email protected]> wrote: > On Monday, October 1, 2012 3:05:05 PM UTC-7, Christian MICHON wrote: >> >> Hi, >> >> as I'm currently refactoring some of my complex jdbc prepared >> statements to a more generic ORM approach, using pure Sequel, I found >> it very difficult to translate such SQL query: >> >> SELECT NAME, COUNT(REV)=0 AS LEAF FROM PROD >> >> I cannot pass the stage beyond count. So far, I'm stuck now with: >> >> DB[:prod].select{[:name,count(:rev).as(:leaf)]}.sql >> => "SELECT NAME, count(REV) AS LEAF FROM PROD" >> >> I could not find how to code the boolean test (equal to 0). Can >> someone with experience on using count+test+aliasing help me? > > > Equality expressions in Sequel are always expressed as hashes: > > DB[:prod].select{[:name, Sequel.as({count(:rev)=>0}, :leaf)]} > > Jeremy >
Hi Jeremy, I remember reading hashes are needed when using equality (I read the docs) but I couldn't figure out how to combine equality with count and 'as'. Looks perfect. I want to come back on my 'statement' done few months back on prepared statements using jdbc. Your architectural choice (staying generic) is indeed the _right_ one. Now that I wrapped my mind around Sequel prepared statements, I'm planning to add these to several of my Sequel models and evaluate the gain. If speed only was needed, I would not do so. I'm shooting for refactoring in order to keep my sinatra application's maintenance easy. Thanks again! -- Christian -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
