[Nitro] [oree.ch] Patchset #1

zimba.tm zimba.tm at gmail.com
Mon Feb 13 07:31:01 EST 2006

On Monday 13 February 2006 12:26, Michael Neumann wrote:
> Am 13.02.2006 um 09:43 schrieb zimba.tm:
> > On Sunday 12 February 2006 23:51, Michael Neumann wrote:
> > How about additional keywords that are dependent of the database,
> > like mysql's
> > auto_incerment or UNSIGNED ?
> I guess this can be done with the existing implementation using
> :extra_sql (I don't remember the correct keyword).
> With :sql_type, you could write:
>    property :age, Integer, :sql_type => "UNSIGNED INT"
> Or auto_increment:
>    property :myid, Integer, :extra_sql => 'auto_increment'
> Even with :sql_type, we wouldn't need :length or :limit at all as we
> could write:
>    property :name, String, :sql_type => "VARCHAR(256)"
> But then, we could do everything directly with:
>    property :name, String, :sql => "VARCHAR(256) DEFAULT '' NOT NULL"
> Regards,
>    Michael
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general

So what is the best ? If you have to know some SQL, why not learn all of it 
instead of a ruby DSL ? Aren't we loosing the pure-ruby approach there ? Also 
what happens if you change your store. Will you have to rewrite all your SQL 
for it ?

To answer all those questions, I have implemented TypeCast. It is now 
integrated in the latest facets. Let me show you how it works :

require 'facet/typecast'
class SqlType
  class << self
    def from_string

Now you should be able to cast your string to an SqlType with 

the `cast_to` method looks for a `to_sql_type` method in the instance and then 
a `from_string` method in the passed class.

Right now it doesn't support additional parameters and I'm not sure if it's a 
good idea to do this. Plus I didn't had a sactisfactional implementation for 

Using this library, you could extend SqlType for any particular store. Now you 
can use the generic conversion and add the store-specific changes to it.

Look a little at the library and let me know what you think. In the meanwhile, 
I'm still working on this.


weblog : http://zimba.oree.ch

More information about the Nitro-general mailing list