Note that there are some explanatory texts on larger screens.

plurals
  1. POGroovyRowResult coerce into domain object
    primarykey
    data
    text
    <p>Given this table:</p> <pre><code>CREATE TABLE todouser ( id SERIAL, email varchar(80) UNIQUE NOT NULL, password varchar(80), registered boolean DEFAULT FALSE, confirmationUri varchar(280), CONSTRAINT todouser_pkey PRIMARY KEY (id) ); </code></pre> <p>and class:</p> <pre><code>class TodoUser { Long id; String email; String password; String confirmationUri; boolean registered; } </code></pre> <p>I am trying to do the following:</p> <pre><code>TodoUser user = sql.firstRow("""SELECT * FROM todouser WHERE email = $email""") </code></pre> <p>i.e. I want Groovy to handle the coercion of the GroovyRowResult into my basic POGO, instead of building it myself as in <a href="https://stackoverflow.com/questions/2002329/coerce-result-row-into-object/2002437#2002437">this answer</a>.</p> <p>I think this is reasonable since GroovyRowResult implements Map and its just a Map key to POGO instance variable name mapping... something which Groovy has some kind of support for.</p> <p>The problem is that, in the PostgreSQL table, 'confirmationUri' is actually showing up as 'confirmationuri'... so the mapping is failing because of the 'U' being in upper case in my POGO.</p> <p>I have tried changing 'confirmationUri' to 'confirmation' in the table and POGO and it works... but just for the record, how would you get around this in Groovy?</p> <p>I seem to remember there being methods you can override in Groovy classes which help in resolving "set/get" calls. But is this the right approach? Is there perhaps some annotation I could use to mark 'confirmationUri' as equivalent to 'confirmationuri' when 'get/set' methods are called? Or perhaps there's some other way to do this in Groovy?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload