Re: Complex SQL queries with JDBI
Thanks for sharing your approach Douglas, Kim. I was wondering what the most elegant way of making the handle available was when 99% of queries are well supported by the @SqlQuery("…"); On Tuesday, October 18, 2016 at 10:09:38 AM UTC-7, Kim Kantola wrote: > > Thank you so much Evan and Douglas for taking the time to help. > I did end up going with your approach Douglas, I am using annotated SQL > where I can, but for the dynamic queries, I am using the jdbi handle and > executing the SQL that way. > > In case anyone else finds this thread looking for similar help, I should > add that in my DAO class, I imported the following class which comes > bundled with dropwizard > org.skife.jdbi.v2.sqlobject.mixins.GetHandlecode here... > > > Then, I made my class implement GetHandle, by doing that, I can then do > > this.getHandle(); > > in order to get access to the database connection. > > > On Friday, October 14, 2016 at 1:15:11 PM UTC-7, Kim Kantola wrote: >> >> Hi All, >> >> I am new to JDBI. I have seen several simple examples of annotating a >> DAO with a query like "Select * from tableName where id=?". >> >> Could someone point me to documentation for more complex queries such as >> searching by a dynamic list of parameters? For example, a user can search >> by name, age, id, height, etc, but I am unaware until runtime which >> combination of these search parameters may come in to my search method. I >> may not get a search value for age, and so do not need to bind anything to >> the search query for that. >> >> Any pointers appreciated, >> ~Kim >> > -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Complex SQL queries with JDBI
Thank you so much Evan and Douglas for taking the time to help. I did end up going with your approach Douglas, I am using annotated SQL where I can, but for the dynamic queries, I am using the jdbi handle and executing the SQL that way. In case anyone else finds this thread looking for similar help, I should add that in my DAO class, I imported the following class which comes bundled with dropwizard org.skife.jdbi.v2.sqlobject.mixins.GetHandlecode here... Then, I made my class implement GetHandle, by doing that, I can then do this.getHandle(); in order to get access to the database connection. On Friday, October 14, 2016 at 1:15:11 PM UTC-7, Kim Kantola wrote: > > Hi All, > > I am new to JDBI. I have seen several simple examples of annotating a DAO > with a query like "Select * from tableName where id=?". > > Could someone point me to documentation for more complex queries such as > searching by a dynamic list of parameters? For example, a user can search > by name, age, id, height, etc, but I am unaware until runtime which > combination of these search parameters may come in to my search method. I > may not get a search value for age, and so do not need to bind anything to > the search query for that. > > Any pointers appreciated, > ~Kim > -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Complex SQL queries with JDBI
Hello Kim, Based on my understanding of your situation, I would advise the approach of using the simplest possible DAO methods and keeping the query complexity within your application code. For instance, if a GET endpoint takes name, age, id, etc as query parameters, your resource method could fire off simple `SELECT * FROM table_name WHERE foo = bar` depending on whatever condition(s) you want. This is simply because I find application code to be easier to test and maintain, in contrast to SQL code inlined as strings in annotations. On Fri, Oct 14, 2016 at 1:15 PM, Kim Kantolawrote: > Hi All, > > I am new to JDBI. I have seen several simple examples of annotating a DAO > with a query like "Select * from tableName where id=?". > > Could someone point me to documentation for more complex queries such as > searching by a dynamic list of parameters? For example, a user can search > by name, age, id, height, etc, but I am unaware until runtime which > combination of these search parameters may come in to my search method. I > may not get a search value for age, and so do not need to bind anything to > the search query for that. > > Any pointers appreciated, > ~Kim > > -- > You received this message because you are subscribed to the Google Groups > "dropwizard-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to dropwizard-user+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Evan Meagher -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-user+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.