|
When Grails generates the database tables for a domain model, is there a way to more definitively specify the data types and lengths used for the table's columns? For example, suppose I have a domain model with the following attributes... String state float salesTaxRate In MySQL, Grails would define these columns as... +-----------------+--------------+ | Field | Type | +-----------------+--------------+ | salesTaxRate | float | | state | varchar(255) | Is there a way to make sure these columns are instead generated as follows? +-----------------+--------------+ | Field | Type | +-----------------+--------------+ | salesTaxRate | decimal(5,2) | | state | char(2) | Is this something that annotations might support? Or better yet, could this information perhaps be derived from the constraints? def constraints = { state(length:2..2,blank:false) salesTaxRate(range:0..100,blank:false) } Of course, if we used the constraints, we'd need a way to specify the number of decimals for any floating point numbers. I'd appreciate hearing any thoughts you might have on this topic. Thanks, Jason |
|
At the moment you would have to write a SQL script or something to
generate your database. Controlling it via constraints would be feasible, but would need to be well thought out. Maybe we can start a wiki page with a proposal? Cheers Graeme On 8/23/06, Jason Rudolph <[hidden email]> wrote: > > > When Grails generates the database tables for a domain model, is there a way > to more definitively specify the data types and lengths used for the table's > columns? For example, suppose I have a domain model with the following > attributes... > > String state > float salesTaxRate > > In MySQL, Grails would define these columns as... > > +-----------------+--------------+ > | Field | Type | > +-----------------+--------------+ > | salesTaxRate | float | > | state | varchar(255) | > > Is there a way to make sure these columns are instead generated as follows? > > +-----------------+--------------+ > | Field | Type | > +-----------------+--------------+ > | salesTaxRate | decimal(5,2) | > | state | char(2) | > > > Is this something that annotations might support? Or better yet, could this > information perhaps be derived from the constraints? > > def constraints = { > state(length:2..2,blank:false) > salesTaxRate(range:0..100,blank:false) > } > > Of course, if we used the constraints, we'd need a way to specify the number > of decimals for any floating point numbers. > > I'd appreciate hearing any thoughts you might have on this topic. > > Thanks, > Jason > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
Thanks, Graeme. I've added the following page in the sandbox area. http://grails.org/Using+Constraints+to+Specify+Database+Column+Types+When+Creating+Tables+from+a+Groovy+Domain+Class Cheers, Jason ----- Original Message ---- From: Graeme Rocher <[hidden email]> To: [hidden email] Sent: Wednesday, August 23, 2006 3:59:54 AM Subject: Re: [grails-user] Specifying Database Column Types When Creating Tables from Groovy Domain Class At the moment you would have to write a
SQL script or something to generate your database. Controlling it via constraints would be feasible, but would need to be well thought out. Maybe we can start a wiki page with a proposal? Cheers Graeme On 8/23/06, Jason Rudolph <[hidden email]> wrote: > > > When Grails generates the database tables for a domain model, is there a way > to more definitively specify the data types and lengths used for the table's > columns? For example, suppose I have a domain model with the following > attributes... > > String state > float salesTaxRate > > In MySQL, Grails would define these columns as... > > +-----------------+--------------+ > | Field | Type | > +-----------------+--------------+ > | salesTaxRate | float | > | state | varchar(255) | > > Is there a way to make sure these columns are instead generated as follows? > > +-----------------+--------------+ > | Field | Type | > +-----------------+--------------+ > | salesTaxRate | decimal(5,2) | > | state | char(2) | > > > Is this something that annotations might support? Or better yet, could this > information perhaps be derived from the constraints? > > def constraints = { > state(length:2..2,blank:false) > salesTaxRate(range:0..100,blank:false) > } > > Of course, if we used the constraints, we'd need a way to specify the number > of decimals for any floating point numbers. > > I'd appreciate hearing any thoughts you might have on this topic. > > Thanks, > Jason > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
Hi, all
I want to talk about a duplication problem. Well, it's not only about database column type mapping, but about the Grails' "constraints" itself. Following is a typical domain class: {code} String homepage def constraints = { homepage(url:true,blank:false) } {code} In this code, we have to type "homepage" twice and it's a duplication. When it comes to database column type mapping problem, we may have to type almost every property names twice. This kind of duplications are huge source of bug. So I prefer following style(it's just a pseudo code): {code} String homepage(url:true,blank:false) {code} And I believe this style fits with "Don't Repeat Yourself" principle. On 8/24/06, Jason Rudolph <[hidden email]> wrote: > > > Thanks, Graeme. I've added the following page in the sandbox area. > > http://grails.org/Using+Constraints+to+Specify+Database+Column+Types+When+Creating+Tables+from+a+Groovy+Domain+Class > > Cheers, > Jason > > > > ----- Original Message ---- > From: Graeme Rocher <[hidden email]> > To: [hidden email] > Sent: Wednesday, August 23, 2006 3:59:54 AM > Subject: Re: [grails-user] Specifying Database Column Types When Creating > Tables from Groovy Domain Class > > At the moment you would have to write a SQL script or something to > generate your database. Controlling it via constraints would be > feasible, but would need to be well thought out. Maybe we can start a > wiki page with a proposal? > > Cheers > Graeme > > On 8/23/06, Jason Rudolph <[hidden email]> wrote: > > > > > > When Grails generates the database tables for a domain model, is there a > way > > to more definitively specify the data types and lengths used for the > table's > > columns? For example, suppose I have a domain model with the following > > attributes... > > > > String state > > float salesTaxRate > > > > In MySQL, Grails would define these columns as... > > > > +-----------------+--------------+ > > | Field | Type | > > +-----------------+--------------+ > > | salesTaxRate | float | > > | state | varchar(255) | > > > > Is there a way to make sure these columns are instead generated as > follows? > > > > +-----------------+--------------+ > > | Field | Type | > > +-----------------+--------------+ > > | salesTaxRate | decimal(5,2) | > > | state | char(2) | > > > > > > Is this something that annotations might support? Or better yet, could > this > > information perhaps be derived from the constraints? > > > > def constraints = { > > state(length:2..2,blank:false) > > salesTaxRate(range:0..100,blank:false) > > } > > > > Of course, if we used the constraints, we'd need a way to specify the > number > > of decimals for any floating point numbers. > > > > I'd appreciate hearing any thoughts you might have on this topic. > > > > Thanks, > > Jason > > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
On 8/25/06, Alan Kang <[hidden email]> wrote:
> Hi, all > > I want to talk about a duplication problem. Well, it's not only about > database column type mapping, but about the Grails' "constraints" > itself. Following is a typical domain class: > > {code} > String homepage > > def constraints = { > homepage(url:true,blank:false) > } > {code} > > In this code, we have to type "homepage" twice and it's a duplication. > When it comes to database column type mapping problem, we may have to > type almost every property names twice. This kind of duplications are > huge source of bug. So I prefer following style(it's just a pseudo > code): > > {code} > String homepage(url:true,blank:false) > {code} > > And I believe this style fits with "Don't Repeat Yourself" principle. Although I agree this violates DRY the above syntax is not valid in Groovy I believe Graeme > > On 8/24/06, Jason Rudolph <[hidden email]> wrote: > > > > > > Thanks, Graeme. I've added the following page in the sandbox area. > > > > http://grails.org/Using+Constraints+to+Specify+Database+Column+Types+When+Creating+Tables+from+a+Groovy+Domain+Class > > > > Cheers, > > Jason > > > > > > > > ----- Original Message ---- > > From: Graeme Rocher <[hidden email]> > > To: [hidden email] > > Sent: Wednesday, August 23, 2006 3:59:54 AM > > Subject: Re: [grails-user] Specifying Database Column Types When Creating > > Tables from Groovy Domain Class > > > > At the moment you would have to write a SQL script or something to > > generate your database. Controlling it via constraints would be > > feasible, but would need to be well thought out. Maybe we can start a > > wiki page with a proposal? > > > > Cheers > > Graeme > > > > On 8/23/06, Jason Rudolph <[hidden email]> wrote: > > > > > > > > > When Grails generates the database tables for a domain model, is there a > > way > > > to more definitively specify the data types and lengths used for the > > table's > > > columns? For example, suppose I have a domain model with the following > > > attributes... > > > > > > String state > > > float salesTaxRate > > > > > > In MySQL, Grails would define these columns as... > > > > > > +-----------------+--------------+ > > > | Field | Type | > > > +-----------------+--------------+ > > > | salesTaxRate | float | > > > | state | varchar(255) | > > > > > > Is there a way to make sure these columns are instead generated as > > follows? > > > > > > +-----------------+--------------+ > > > | Field | Type | > > > +-----------------+--------------+ > > > | salesTaxRate | decimal(5,2) | > > > | state | char(2) | > > > > > > > > > Is this something that annotations might support? Or better yet, could > > this > > > information perhaps be derived from the constraints? > > > > > > def constraints = { > > > state(length:2..2,blank:false) > > > salesTaxRate(range:0..100,blank:false) > > > } > > > > > > Of course, if we used the constraints, we'd need a way to specify the > > number > > > of decimals for any floating point numbers. > > > > > > I'd appreciate hearing any thoughts you might have on this topic. > > > > > > Thanks, > > > Jason > > > > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
Yes I know so I did say it's just a pseudo code. :-)
I've wrote the pseudo code because I'm not sure about most groovy way to represent that code. Could you please suggest one? On 8/29/06, Graeme Rocher <[hidden email]> wrote: > On 8/25/06, Alan Kang <[hidden email]> wrote: > > Hi, all > > > > I want to talk about a duplication problem. Well, it's not only about > > database column type mapping, but about the Grails' "constraints" > > itself. Following is a typical domain class: > > > > {code} > > String homepage > > > > def constraints = { > > homepage(url:true,blank:false) > > } > > {code} > > > > In this code, we have to type "homepage" twice and it's a duplication. > > When it comes to database column type mapping problem, we may have to > > type almost every property names twice. This kind of duplications are > > huge source of bug. So I prefer following style(it's just a pseudo > > code): > > > > {code} > > String homepage(url:true,blank:false) > > {code} > > > > And I believe this style fits with "Don't Repeat Yourself" principle. > > Although I agree this violates DRY the above syntax is not valid in > Groovy I believe > > Graeme > > > > > On 8/24/06, Jason Rudolph <[hidden email]> wrote: > > > > > > > > > Thanks, Graeme. I've added the following page in the sandbox area. > > > > > > http://grails.org/Using+Constraints+to+Specify+Database+Column+Types+When+Creating+Tables+from+a+Groovy+Domain+Class > > > > > > Cheers, > > > Jason > > > > > > > > > > > > ----- Original Message ---- > > > From: Graeme Rocher <[hidden email]> > > > To: [hidden email] > > > Sent: Wednesday, August 23, 2006 3:59:54 AM > > > Subject: Re: [grails-user] Specifying Database Column Types When Creating > > > Tables from Groovy Domain Class > > > > > > At the moment you would have to write a SQL script or something to > > > generate your database. Controlling it via constraints would be > > > feasible, but would need to be well thought out. Maybe we can start a > > > wiki page with a proposal? > > > > > > Cheers > > > Graeme > > > > > > On 8/23/06, Jason Rudolph <[hidden email]> wrote: > > > > > > > > > > > > When Grails generates the database tables for a domain model, is there a > > > way > > > > to more definitively specify the data types and lengths used for the > > > table's > > > > columns? For example, suppose I have a domain model with the following > > > > attributes... > > > > > > > > String state > > > > float salesTaxRate > > > > > > > > In MySQL, Grails would define these columns as... > > > > > > > > +-----------------+--------------+ > > > > | Field | Type | > > > > +-----------------+--------------+ > > > > | salesTaxRate | float | > > > > | state | varchar(255) | > > > > > > > > Is there a way to make sure these columns are instead generated as > > > follows? > > > > > > > > +-----------------+--------------+ > > > > | Field | Type | > > > > +-----------------+--------------+ > > > > | salesTaxRate | decimal(5,2) | > > > > | state | char(2) | > > > > > > > > > > > > Is this something that annotations might support? Or better yet, could > > > this > > > > information perhaps be derived from the constraints? > > > > > > > > def constraints = { > > > > state(length:2..2,blank:false) > > > > salesTaxRate(range:0..100,blank:false) > > > > } > > > > > > > > Of course, if we used the constraints, we'd need a way to specify the > > > number > > > > of decimals for any floating point numbers. > > > > > > > > I'd appreciate hearing any thoughts you might have on this topic. > > > > > > > > Thanks, > > > > Jason > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe from this list please visit: > > > > > > http://xircles.codehaus.org/manage_email > > > > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Jason Rudolph
Personally, I would guess that the following be Groovy-ish and DRY, but
might be a hell of a lot of work (maybe too much?) to implement via proxies, etc. It would also address the storage type issue. But it makes defining simple objects more complicated, because data types need to be specified somehow; also, this might slow down Grails' startup time with all the additional work needed. So my thinking is to continue supporting the current means of defining props, but support a new builder-style of specifying props. Thoughts on this? def homepage = { // support a complex definition. type(String.class) storage(type:varchar, length: 8) constraints(url:true,blank:false) } def description = { // be sure to support LOB types like CLOB type(String.class) storage(type:clob) optional() } String name // continue to support simple typed property definitions as well as an alternative - Daiji Alan Kang wrote: > Yes I know so I did say it's just a pseudo code. :-) > > I've wrote the pseudo code because I'm not sure about most groovy way > to represent that code. > > Could you please suggest one? > > On 8/29/06, Graeme Rocher <[hidden email]> wrote: >> On 8/25/06, Alan Kang <[hidden email]> wrote: >> > Hi, all >> > >> > I want to talk about a duplication problem. Well, it's not only about >> > database column type mapping, but about the Grails' "constraints" >> > itself. Following is a typical domain class: >> > >> > {code} >> > String homepage >> > >> > def constraints = { >> > homepage(url:true,blank:false) >> > } >> > {code} >> > >> > In this code, we have to type "homepage" twice and it's a duplication. >> > When it comes to database column type mapping problem, we may have to >> > type almost every property names twice. This kind of duplications are >> > huge source of bug. So I prefer following style(it's just a pseudo >> > code): >> > >> > {code} >> > String homepage(url:true,blank:false) >> > {code} >> > >> > And I believe this style fits with "Don't Repeat Yourself" principle. >> >> Although I agree this violates DRY the above syntax is not valid in >> Groovy I believe >> >> Graeme >> >> > >> > On 8/24/06, Jason Rudolph <[hidden email]> wrote: >> > > >> > > >> > > Thanks, Graeme. I've added the following page in the sandbox area. >> > > >> > > >> >> >> > > >> > > Cheers, >> > > Jason >> > > >> > > >> > > >> > > ----- Original Message ---- >> > > From: Graeme Rocher <[hidden email]> >> > > To: [hidden email] >> > > Sent: Wednesday, August 23, 2006 3:59:54 AM >> > > Subject: Re: [grails-user] Specifying Database Column Types When >> Creating >> > > Tables from Groovy Domain Class >> > > >> > > At the moment you would have to write a SQL script or something to >> > > generate your database. Controlling it via constraints would be >> > > feasible, but would need to be well thought out. Maybe we can >> start a >> > > wiki page with a proposal? >> > > >> > > Cheers >> > > Graeme >> > > >> > > On 8/23/06, Jason Rudolph <[hidden email]> wrote: >> > > > >> > > > >> > > > When Grails generates the database tables for a domain model, >> is there a >> > > way >> > > > to more definitively specify the data types and lengths used >> for the >> > > table's >> > > > columns? For example, suppose I have a domain model with the >> following >> > > > attributes... >> > > > >> > > > String state >> > > > float salesTaxRate >> > > > >> > > > In MySQL, Grails would define these columns as... >> > > > >> > > > +-----------------+--------------+ >> > > > | Field | Type | >> > > > +-----------------+--------------+ >> > > > | salesTaxRate | float | >> > > > | state | varchar(255) | >> > > > >> > > > Is there a way to make sure these columns are instead generated as >> > > follows? >> > > > >> > > > +-----------------+--------------+ >> > > > | Field | Type | >> > > > +-----------------+--------------+ >> > > > | salesTaxRate | decimal(5,2) | >> > > > | state | char(2) | >> > > > >> > > > >> > > > Is this something that annotations might support? Or better >> yet, could >> > > this >> > > > information perhaps be derived from the constraints? >> > > > >> > > > def constraints = { >> > > > state(length:2..2,blank:false) >> > > > salesTaxRate(range:0..100,blank:false) >> > > > } >> > > > >> > > > Of course, if we used the constraints, we'd need a way to >> specify the >> > > number >> > > > of decimals for any floating point numbers. >> > > > >> > > > I'd appreciate hearing any thoughts you might have on this topic. >> > > > >> > > > Thanks, >> > > > Jason >> > > > >> > > >> > > >> --------------------------------------------------------------------- >> > > To unsubscribe from this list please visit: >> > > >> > > http://xircles.codehaus.org/manage_email >> > > >> > > >> > > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe from this list please visit: >> > >> > http://xircles.codehaus.org/manage_email >> > >> > >> >> --------------------------------------------------------------------- >> To unsubscribe from this list please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
I agree on the issues you made and also the solution. And the notation
you suggested also looks good to me. :-) Regards On 9/3/06, D T <[hidden email]> wrote: > Personally, I would guess that the following be Groovy-ish and DRY, but > might be a hell of a lot of work (maybe too much?) to implement via > proxies, etc. It would also address the storage type issue. But it > makes defining simple objects more complicated, because data types need > to be specified somehow; also, this might slow down Grails' startup time > with all the additional work needed. So my thinking is to continue > supporting the current means of defining props, but support a new > builder-style of specifying props. Thoughts on this? > > def homepage = { // support a complex definition. > type(String.class) > storage(type:varchar, length: 8) > constraints(url:true,blank:false) > } > def description = { // be sure to support LOB types like CLOB > type(String.class) > storage(type:clob) > optional() > } > String name // continue to support simple typed property definitions > as well as an alternative > > - Daiji > > Alan Kang wrote: > > Yes I know so I did say it's just a pseudo code. :-) > > > > I've wrote the pseudo code because I'm not sure about most groovy way > > to represent that code. > > > > Could you please suggest one? > > > > On 8/29/06, Graeme Rocher <[hidden email]> wrote: > >> On 8/25/06, Alan Kang <[hidden email]> wrote: > >> > Hi, all > >> > > >> > I want to talk about a duplication problem. Well, it's not only about > >> > database column type mapping, but about the Grails' "constraints" > >> > itself. Following is a typical domain class: > >> > > >> > {code} > >> > String homepage > >> > > >> > def constraints = { > >> > homepage(url:true,blank:false) > >> > } > >> > {code} > >> > > >> > In this code, we have to type "homepage" twice and it's a duplication. > >> > When it comes to database column type mapping problem, we may have to > >> > type almost every property names twice. This kind of duplications are > >> > huge source of bug. So I prefer following style(it's just a pseudo > >> > code): > >> > > >> > {code} > >> > String homepage(url:true,blank:false) > >> > {code} > >> > > >> > And I believe this style fits with "Don't Repeat Yourself" principle. > >> > >> Although I agree this violates DRY the above syntax is not valid in > >> Groovy I believe > >> > >> Graeme > >> > >> > > >> > On 8/24/06, Jason Rudolph <[hidden email]> wrote: > >> > > > >> > > > >> > > Thanks, Graeme. I've added the following page in the sandbox area. > >> > > > >> > > > >> > http://grails.org/Using+Constraints+to+Specify+Database+Column+Types+When+Creating+Tables+from+a+Groovy+Domain+Class > > >> > >> > > > >> > > Cheers, > >> > > Jason > >> > > > >> > > > >> > > > >> > > ----- Original Message ---- > >> > > From: Graeme Rocher <[hidden email]> > >> > > To: [hidden email] > >> > > Sent: Wednesday, August 23, 2006 3:59:54 AM > >> > > Subject: Re: [grails-user] Specifying Database Column Types When > >> Creating > >> > > Tables from Groovy Domain Class > >> > > > >> > > At the moment you would have to write a SQL script or something to > >> > > generate your database. Controlling it via constraints would be > >> > > feasible, but would need to be well thought out. Maybe we can > >> start a > >> > > wiki page with a proposal? > >> > > > >> > > Cheers > >> > > Graeme > >> > > > >> > > On 8/23/06, Jason Rudolph <[hidden email]> wrote: > >> > > > > >> > > > > >> > > > When Grails generates the database tables for a domain model, > >> is there a > >> > > way > >> > > > to more definitively specify the data types and lengths used > >> for the > >> > > table's > >> > > > columns? For example, suppose I have a domain model with the > >> following > >> > > > attributes... > >> > > > > >> > > > String state > >> > > > float salesTaxRate > >> > > > > >> > > > In MySQL, Grails would define these columns as... > >> > > > > >> > > > +-----------------+--------------+ > >> > > > | Field | Type | > >> > > > +-----------------+--------------+ > >> > > > | salesTaxRate | float | > >> > > > | state | varchar(255) | > >> > > > > >> > > > Is there a way to make sure these columns are instead generated as > >> > > follows? > >> > > > > >> > > > +-----------------+--------------+ > >> > > > | Field | Type | > >> > > > +-----------------+--------------+ > >> > > > | salesTaxRate | decimal(5,2) | > >> > > > | state | char(2) | > >> > > > > >> > > > > >> > > > Is this something that annotations might support? Or better > >> yet, could > >> > > this > >> > > > information perhaps be derived from the constraints? > >> > > > > >> > > > def constraints = { > >> > > > state(length:2..2,blank:false) > >> > > > salesTaxRate(range:0..100,blank:false) > >> > > > } > >> > > > > >> > > > Of course, if we used the constraints, we'd need a way to > >> specify the > >> > > number > >> > > > of decimals for any floating point numbers. > >> > > > > >> > > > I'd appreciate hearing any thoughts you might have on this topic. > >> > > > > >> > > > Thanks, > >> > > > Jason > >> > > > > >> > > > >> > > > >> --------------------------------------------------------------------- > >> > > To unsubscribe from this list please visit: > >> > > > >> > > http://xircles.codehaus.org/manage_email > >> > > > >> > > > >> > > > >> > > >> > --------------------------------------------------------------------- > >> > To unsubscribe from this list please visit: > >> > > >> > http://xircles.codehaus.org/manage_email > >> > > >> > > >> > >> --------------------------------------------------------------------- > >> To unsubscribe from this list please visit: > >> > >> http://xircles.codehaus.org/manage_email > >> > >> > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
