[jifty-devel] user-defined data types

Edgar Whipple jifty at misterwhipple.com
Wed Feb 21 22:35:51 EST 2007


I don't see anything in the jifty-devel archives about user-defined data
types. Has there been any discussion?

They wouldn't necessarily have to be supported in the database engine,
although that might be useful. I can think of a couple of ways to do it
at the model-declaration level.

1. Use a simple string for the repeated column attributes.

2. Define a subclass of Jifty::DBI::Column, the instances of which carry
the repeated attributes.

3. Define a separate subclass of Jifty::DBI::Column for each
user-defined type.

Here are some guesses about how they might be used.

<code>

package MyJiftyApp::Model::MyModel1;
use Jifty::DBI::Schema;

# setting up nos. 1 and 2. 
# These would probably be in a separate package
my $ud_type_string = qq(
    type => 'text',
    max_length => 128,
    render_as => 'Text',
    mandatory => '',
)
my $ud_type_object 
    = Jifty::DBI::Column::UserDefined::Concrete
        ->new( {type => 'text', @etcetera} )
        

use MyJiftyApp::Record schema {

    # 1. example of using type definition string
    column firstname =>
        label is 'Firstname',
        since '0.0.1',
        ud_type is $ud_type_string;

    # 2. example of concrete Column subclass
    column surname =>
        label is 'Surname',
        since '0.0.1'
        ud_type is $ud_type_object;

    # 3. example of abstract Column subclass
    column middlename =>
        based_on MyJiftyApp::UserType::MyUserType1,
        label is 'Middle',
        since '0.0.1';

}

package MyJiftyApp::UserTypes::MyUserType1;
use Jifty::DBI::Column::UserDefined::Abstract;
### and then goodness knows what goes here.

</code>

Each of these involves adding the indicated keyword to
Jifty::DBI::Schema. We might also want a 'not' keyword, e.g. 'is not
mandatory' in the model overrides 'is mandatory' in the reusable column
type.

-Edgar

PS These are just top-of-my-head scribbles, so don't judge too harshly. 

-- 
ln -s /dev/null ~/.sig



More information about the jifty-devel mailing list