[Rt-commit] r3905 - in Jifty-DBI/trunk: . lib/Jifty/DBI t
alexmv at bestpractical.com
alexmv at bestpractical.com
Wed Oct 5 00:12:54 EDT 2005
Author: alexmv
Date: Wed Oct 5 00:12:53 2005
New Revision: 3905
Added:
Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm
Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm
Jifty-DBI/trunk/t/01records.t
Jifty-DBI/trunk/t/01searches.t
Jifty-DBI/trunk/t/02records_object.t
Jifty-DBI/trunk/t/06filter_datetime.t
Jifty-DBI/trunk/t/06filter_truncate.t
Jifty-DBI/trunk/t/06filter_utf8.t
Jifty-DBI/trunk/t/11schema_records.t
Jifty-DBI/trunk/t/testmodels.pl
Log:
r6614 at zoq-fot-pik: chmrr | 2005-10-04 18:56:27 -0400
* Declaritive schema syntax.
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Collection.pm Wed Oct 5 00:12:53 2005
@@ -76,6 +76,7 @@
my $class = ref($proto) || $proto;
my $self = {};
bless( $self, $class );
+ $self->record_class( $proto->record_class ) if ref $proto;
$self->_init(@_);
return ($self);
}
@@ -501,17 +502,45 @@
return ( $self->{'items'} || [] );
}
-=head2 new_item
+sub new_item {
+ my $self = shift;
+ my $class =$self->record_class();
+
+ die "Jifty::DBI::Collection needs to be subclassed; override new_item\n"
+ unless $class;
+
+ $class->require();
+ return $class->new($self->_handle);
+}
+
+=head2 record_class
+
+Returns the record class which this is a collection of; override this
+to subclass. Or, pass it the name of a class an an argument after
+creating a C<JFDI::Collection> object to create an 'anonymous'
+collection class.
+
+If you haven't specified a record class, this eturns a best guess at
+the name of the record class for this collection.
-new_item must be subclassed. It is used by Jifty::DBI::Collection to
-create record objects for each row returned from the database.
+It uses a simple heuristic to determine the record class name -- It
+chops "Collection" off its own name. If you want to name your records
+and collections differently, go right ahead, but don't say we didn't
+warn you
=cut
-sub new_item {
+sub record_class {
my $self = shift;
-
- die "Jifty::DBI::Collection needs to be subclassed; override new_item\n";
+ if (@_) {
+ $self->{record_class} = shift if (@_);
+ }
+ elsif (not $self->{record_class}) {
+ my $class = ref($self);
+ $class =~ s/Collection$//;
+ $self->{record_class} = $class;
+ }
+ return $self->{record_class};
}
=head2 redo_search
@@ -1399,6 +1428,13 @@
return $self->{table};
}
+sub refers_to (@) {
+ my $class = shift;
+ my (%args) = @_;
+
+ warn "Check if $class can $args{by}\n";
+ return (refers_to => $class, %args);
+}
1;
__END__
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Column.pm Wed Oct 5 00:12:53 2005
@@ -11,40 +11,33 @@
type
default
validator
- boolean
readable writable
- length
- refers_to_collection_class
- refers_to_record_class
+ length
+ null
+ refers_to by
alias_for_column
/;
=head1 NAME
-Jifty::DB::Column
+Jifty::DBI::Column
=head1 DESCRIPTION
-This class encapsulate's a single column in a Jifty::DBI::Record table description. It replaces the _accessible method in
+This class encapsulate's a single column in a Jifty::DBI::Record table
+description. It replaces the _accessible method in
L<Jifty::DBI::Record>.
-It has the following accessors: C<name type default validator boolean refers_to readable writable length>.
+It has the following accessors: C<name type default validator boolean
+refers_to readable writable length>.
=cut
-
-sub new {
- my $class = shift;
- my $self = {};
- bless $self => $class;
- return $self;
-}
-
sub is_numeric {
my $self = shift;
- if ($self->type =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i ) {
+ if ($self->type =~ /INT|NUMERIC|DECIMAL|REAL|DOUBLE|FLOAT/i ) {
return 1;
}
return 0;
@@ -55,5 +48,4 @@
*read = \&readable;
*write = \&writable;
-
1;
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/HasFilters.pm Wed Oct 5 00:12:53 2005
@@ -41,8 +41,8 @@
sub input_filters {
my $self = shift;
if( @_ ) { # setting
- my @values = map { UNIVERSAL::isa($_, 'ARRAY')? @$_: $_ } @_;
- return $self->_input_filters_accessor( @values );
+ my @values = map { UNIVERSAL::isa($_, 'ARRAY')? @$_: $_ } @_;
+ return $self->_input_filters_accessor( @values );
}
return grep $_, $self->_input_filters_accessor;
@@ -61,7 +61,8 @@
sub output_filters {
my $self = shift;
if( @_ ) { # setting
- $self->_output_filters_accessor( @_ );
+ my @values = map { UNIVERSAL::isa($_, 'ARRAY')? @$_: $_ } @_;
+ $self->_output_filters_accessor( @values );
}
my @values = grep $_, $self->_output_filters_accessor;
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record.pm Wed Oct 5 00:12:53 2005
@@ -303,17 +303,16 @@
unless ($column) {
my ( $package, $filename, $line ) = caller;
die "$AUTOLOAD Unimplemented in $package. ($filename line $line) \n";
-
}
- no strict 'refs'; # We're going to be defining subs
+ no strict 'refs'; # We're going to be defining subs
if ( $action eq 'read' and $column->readable ) {
- if ( $column->refers_to_record_class ) {
+ if ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record") ) {
*{$AUTOLOAD}
= sub { $_[0]->_to_record( $column_name, $_[0]->__value($column_name) ) };
}
- elsif ( $column->refers_to_collection_class ) {
+ elsif ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Collection") ) {
*{$AUTOLOAD} = sub { $_[0]->_collection_value($column_name) };
}
else {
@@ -325,25 +324,25 @@
if ( $action eq 'write' ) {
if ( $column->writable ) {
- if ( $column->refers_to_record_class ) {
- *{$AUTOLOAD} = sub {
- my $self = shift;
- my $val = shift;
-
- $val = $val->id
- if UNIVERSAL::isa( $val, 'Jifty::DBI::Record' );
- return ( $self->_set( column => $column_name, value => $val ) );
- };
- }
- else {
- *{$AUTOLOAD} = sub {
- return ( $_[0]->_set( column => $column_name, value => $_[1] ) );
- };
- }
- goto &$AUTOLOAD;
- } else {
+ if ( UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record") ) {
+ *{$AUTOLOAD} = sub {
+ my $self = shift;
+ my $val = shift;
+
+ $val = $val->id
+ if UNIVERSAL::isa( $val, 'Jifty::DBI::Record' );
+ return ( $self->_set( column => $column_name, value => $val ) );
+ };
+ }
+ else {
+ *{$AUTOLOAD} = sub {
+ return ( $_[0]->_set( column => $column_name, value => $_[1] ) );
+ };
+ }
+ goto &$AUTOLOAD;
+ } else {
return (0, 'Immutable field');
- }
+ }
}
elsif ( $action eq 'validate' ) {
*{$AUTOLOAD}
@@ -419,7 +418,8 @@
=head2 _primary_keys
-Return our primary keys. (Subclasses should override this, but our default is that we have one primary key, named 'id'.)
+Return our primary keys. (Subclasses should override this, but our
+default is that we have one primary key, named 'id'.)
=cut
@@ -438,78 +438,27 @@
=head2 _init_columns
-Turns your sub schema into a set of column objects
+Sets up the primary key columns.
=cut
sub _init_columns {
my $self = shift;
- $self->COLUMNS({}); # Clear out the columns hash
+ return if defined $self->COLUMNS;
+
+ $self->COLUMNS({});
foreach my $column_name ( @{$self->_primary_keys} ) {
my $column = $self->add_column($column_name);
$column->writable(0);
+ $column->readable(1);
+ $column->type('serial');
+ $column->null(0);
}
-
- my $schema = $self->schema;
-
- for my $column_name ( keys %$schema ) {
- my $column = $self->add_column($column_name);
- my $meta = $schema->{ $column_name } || {};
-
- # Default, everything readable
- $column->readable( delete $meta->{'read'} || 1 );
-
- # Default, everything writable except columns of the pkey
- if ( $meta->{'write'} ) {
- $column->writable( $meta->{'write'} );
- } elsif (not defined $column->writable) { # don't want to make pkeys writable
- $column->writable(1);
- }
- delete $meta->{'write'};
-
- # Next time, all-lower hash keys
- my $type = delete $meta->{'type'} ||
- delete $meta->{'TYPE'};
-
- if ($type) {
- $column->type($type);
- }
-
- my $refclass = delete $meta->{'REFERENCES'} ||
- delete $meta->{'references'};
-
- if ($refclass) {
- $refclass->require();
- if ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Record' ) ) {
- if ( $column_name =~ /(.*)_id$/ ) {
-
- my $virtual_column = $self->add_column($1);
- $virtual_column->refers_to_record_class($refclass);
- $virtual_column->alias_for_column($column_name);
- $virtual_column->readable( delete $meta->{'read'} || 1);
- }
- else {
- $column->refers_to_record_class($refclass);
- }
-
- }
- elsif ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Collection' ) ) {
- $column->refers_to_collection_class($refclass);
- }
- else {
- warn "Error: $refclass neither Record nor Collection";
- }
- }
- for my $attr( keys %$meta) {
- next unless $column->can( $attr );
- $column->$attr( $meta->{$attr} );
- }
- }
-
}
+
=head2 _to_record COLUMN VALUE
This B<PRIVATE> method takes a column name and a value for that column.
@@ -531,12 +480,11 @@
my $column = $self->column($column_name);
- my $classname = $column->refers_to_record_class();
+ my $classname = $column->refers_to();
return unless defined $value;
return undef unless $classname;
-
return unless UNIVERSAL::isa( $classname, 'Jifty::DBI::Record' );
# XXX TODO FIXME we need to figure out the right way to call new here
@@ -553,18 +501,14 @@
my $method_name = shift;
return unless defined $method_name;
- my $schema = $self->schema;
- my $description = $schema->{$method_name};
- return unless $description;
-
- my $classname = $description->{'REFERENCES'};
+ my $column = $self->column($method_name);
+ my $classname = $column->refers_to();
+ return undef unless $classname;
return unless UNIVERSAL::isa( $classname, 'Jifty::DBI::Collection' );
my $coll = $classname->new( handle => $self->_handle );
-
- $coll->limit( FIELD => $description->{'KEY'}, VALUE => $self->id );
-
+ $coll->limit( FIELD => $column->by(), VALUE => $self->id );
return $coll;
}
@@ -990,7 +934,8 @@
unless ($column) {
die "$column_name isn't a column we know about"
}
- if ( $column->readable and $column->refers_to_record_class ) {
+ if ( $column->readable and $column->refers_to
+ and UNIVERSAL::isa($column->refers_to, "Jifty::DBI::Record")) {
$attribs{$column_name} = $attribs{$column_name}->id
if UNIVERSAL::isa( $attribs{$column_name}, 'Jifty::DBI::Record' );
}
@@ -1106,15 +1051,22 @@
=head2 schema
-You must subclass schema to return your table's columns.
-
-XXX: See L<Jifty::DBI::SchemaGenerator> (I bet)
+Deprecated.
=cut
-# This stub is here to prevent a call to AUTOLOAD
-sub schema {}
+sub schema {
+ my $self = shift;
+ use Carp;
+ croak "Deprecated";
+}
+sub refers_to (@) {
+ my $class = shift;
+ my (%args) = @_;
+
+ return (refers_to => $class, %args);
+}
sub _filters
{
Added: Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
==============================================================================
--- (empty file)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm Wed Oct 5 00:12:53 2005
@@ -0,0 +1,113 @@
+package Jifty::DBI::Schema;
+use Exporter::Lite;
+our @EXPORT = qw(column type default validator immutable length not_null valid_values input_filters output_filters mandatory is by are on);
+
+our $SCHEMA;
+sub column {
+ my $name = shift;
+
+ my $from = (caller)[0];
+ $from =~ s/::Schema//;
+ $from->_init_columns;
+
+ my @args = (name => $name,
+ readable => 1,
+ writable => 1,
+ null => 1,
+ @_,
+ );
+
+ my $column = Jifty::DBI::Column->new();
+ while (@args) {
+ my ($method, $arguments) = splice @args, 0, 2;
+ $column->$method($arguments);
+ }
+
+ if (my $refclass = $column->refers_to) {
+ $refclass->require();
+ $column->type('integer');
+
+ if ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Record' ) ) {
+ if ( $name =~ /(.*)_id$/ ) {
+ my $virtual_column = $from->add_column($1);
+ $virtual_column->refers_to($refclass);
+ $virtual_column->alias_for_column($name);
+ }
+ else {
+ $column->refers_to($refclass);
+ }
+
+ }
+ elsif ( UNIVERSAL::isa( $refclass, 'Jifty::DBI::Collection' ) ) {
+ $column->by('id') unless $column->by;
+ }
+ else {
+ warn "Error: $refclass neither Record nor Collection";
+ }
+ }
+
+ $from->COLUMNS->{$name} = $column;
+}
+
+sub type ($) {
+ return (type => shift);
+}
+
+sub default ($) {
+ return (default => shift);
+}
+
+sub validator ($) {
+ return (validator => shift);
+}
+
+sub immutable () {
+ return ([writable => 0]);
+}
+
+sub length ($) {
+ return (length => shift);
+}
+
+sub not_null () {
+ return ([null => 0]);
+}
+
+sub input_filters ($) {
+ return (input_filters => shift);
+}
+
+sub output_filters ($) {
+ return (output_filters => shift);
+}
+
+
+
+sub mandatory () {
+ return ([mandatory => 1]);
+}
+
+sub valid_values ($) {
+ return (valid_values => shift);
+}
+
+
+
+sub is ($) {
+ my $thing = shift;
+ return ref $thing ? @{$thing} : $thing;
+}
+
+sub by ($) {
+ return (by => shift);
+}
+
+sub are (@) {
+ return [@_];
+}
+
+sub on ($) {
+ return (self => shift);
+}
+
+1;
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/SchemaGenerator.pm Wed Oct 5 00:12:53 2005
@@ -182,45 +182,27 @@
my $model = shift;
my $table_name = $model->table;
- my $schema = $model->schema;
-
- my $primary = "id"; # TODO allow override
- my $primary_col = DBIx::DBSchema::Column->new(
- { name => $primary,
- type => 'serial',
- null => 'NOT NULL',
- }
- );
-
- my @cols = ($primary_col);
+ my @columns = $model->columns;
+ my @cols;
# The sort here is to make it predictable, so that we can write tests.
- for my $field ( sort keys %$schema ) {
-
+ for my $column ( sort {$a->name cmp $b->name} @columns) {
# Skip foreign keys
-
- next
- if defined $schema->{$field}->{'REFERENCES'}
- and defined $schema->{$field}->{'KEY'};
-
- # TODO XXX FIXME
- # In lieu of real reference support, make references just integers
- $schema->{$field}{'TYPE'} = 'integer'
- if $schema->{$field}{'REFERENCES'};
+ next if defined $column->refers_to and defined $column->by;
push @cols,
DBIx::DBSchema::Column->new(
- { name => $field,
- type => $schema->{$field}{'TYPE'},
- null => 'NULL',
- default => $schema->{$field}{'DEFAULT'},
+ { name => $column->name,
+ type => $column->name,
+ null => $column->null,
+ default => $column->default,
}
);
}
my $table = DBIx::DBSchema::Table->new(
{ name => $table_name,
- primary_key => $primary,
+ primary_key => "id",
columns => \@cols,
}
);
Modified: Jifty-DBI/trunk/t/01records.t
==============================================================================
--- Jifty-DBI/trunk/t/01records.t (original)
+++ Jifty-DBI/trunk/t/01records.t Wed Oct 5 00:12:53 2005
@@ -38,6 +38,7 @@
is( $rec->_accessible('id' => 'write'), 0, 'id is not accessible for write' );
is( $rec->_accessible('id'), undef, "any field is not accessible in undefined mode" );
is( $rec->_accessible('unexpected_field' => 'read'), undef, "field doesn't exist and can't be accessible for read" );
+
is_deeply( [sort($rec->readable_attributes)], [sort qw(employee_id id name phone)], 'readable attributes' );
is_deeply( [sort($rec->writable_attributes)], [sort qw(employee_id name phone)], 'writable attributes' );
@@ -196,9 +197,7 @@
1;
-
package TestApp::Address;
-
use base qw/Jifty::DBI::Record/;
sub validate_name
@@ -208,19 +207,6 @@
return 1;
}
-sub schema {
-
- {
-
- id => { TYPE => 'int(11)' },
- name => { TYPE => 'varchar(14)', DEFAULT => ''},
- phone => { TYPE => 'varchar(18)', length => 18, DEFAULT => ''},
- employee_id => { TYPE => 'int(8)', DEFAULT => ''},
-
-}
-
-}
-
sub schema_mysql {
<<EOF;
CREATE TEMPORARY TABLE addresses (
@@ -258,3 +244,23 @@
}
1;
+
+package TestApp::Address::Schema;
+BEGIN {
+use Jifty::DBI::Schema;
+
+column name =>
+ type is 'varchar(14)',
+ default is '';
+
+column phone =>
+ type is 'varchar(18)',
+ length => 18,
+ default is '';
+
+column employee_id =>
+ type is 'int(8)',
+ default is '';
+}
+1;
+
Modified: Jifty-DBI/trunk/t/01searches.t
==============================================================================
--- Jifty-DBI/trunk/t/01searches.t (original)
+++ Jifty-DBI/trunk/t/01searches.t Wed Oct 5 00:12:53 2005
@@ -32,7 +32,7 @@
my $count_all = init_data( 'TestApp::User', $handle );
ok( $count_all, "init users data" );
- my $users_obj = TestApp::Users->new( $handle );
+ my $users_obj = TestApp::UserCollection->new( $handle );
isa_ok( $users_obj, 'Jifty::DBI::Collection' );
is( $users_obj->_handle, $handle, "same handle as we used in constructor");
@@ -213,19 +213,6 @@
$self->_handle($handle);
}
-sub schema {
- {
- id =>
- {read => 1, type => 'int(11)' },
- login =>
- {read => 1, write => 1, type => 'varchar(18)' },
- name =>
- {read => 1, write => 1, type => 'varchar(36)' },
- phone =>
- {read => 1, write => 1, type => 'varchar(18)', default => ''},
- }
-}
-
sub init_data {
return (
[ 'login', 'name', 'phone' ],
@@ -238,7 +225,18 @@
1;
-package TestApp::Users;
+package TestApp::User::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+
+ column login => type is 'varchar(18)';
+ column name => type is 'varchar(36)';
+ column phone => type is 'varchar(18)', default is '';
+}
+
+1;
+
+package TestApp::UserCollection;
# use TestApp::User;
use base qw/Jifty::DBI::Collection/;
@@ -249,11 +247,5 @@
$self->table('users');
}
-sub new_item
-{
- my $self = shift;
- return TestApp::User->new( $self->_handle );
-}
-
1;
Modified: Jifty-DBI/trunk/t/02records_object.t
==============================================================================
--- Jifty-DBI/trunk/t/02records_object.t (original)
+++ Jifty-DBI/trunk/t/02records_object.t Wed Oct 5 00:12:53 2005
@@ -32,7 +32,7 @@
my $emp = TestApp::Employee->new($handle);
my $e_id = $emp->create( Name => 'RUZ' );
- ok($e_id, "Got an ide for the new emplyee");
+ ok($e_id, "Got an id for the new emplyee");
my $phone = TestApp::Phone->new($handle);
isa_ok( $phone, 'TestApp::Phone', "it's a TestApp::Phone");
my $p_id = $phone->create( employee => $e_id, phone => '+7(903)264-03-51');
@@ -99,44 +99,35 @@
} ]
}
-package TestApp::Employee;
+
+package TestApp::Employee;
use base qw/Jifty::DBI::Record/;
-use vars qw/$VERSION/;
-$VERSION=0.01;
-sub schema {
- {
-
- id =>
- {read => 1, type => 'int(11)'},
- name =>
- {read => 1, write => 1, type => 'varchar(18)'},
+1;
+
+package TestApp::Employee::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
- }
+ column name => type is 'varchar(18)';
}
1;
-package TestApp::Phone;
-use vars qw/$VERSION/;
-$VERSION=0.01;
+package TestApp::Phone;
use base qw/Jifty::DBI::Record/;
-sub schema {
- {
-
- id =>
- {read => 1, type => 'int(11)'},
- employee =>
- {read => 1, write => 1, type => 'int(11)', references => 'TestApp::Employee' },
- phone =>
- {read => 1, write => 1, type => 'varchar(18)'},
+1;
- }
-}
+package TestApp::Phone::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+ column employee => refers_to TestApp::Employee;
+ column phone => type 'varchar(18)';
+}
1;
Modified: Jifty-DBI/trunk/t/06filter_datetime.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_datetime.t (original)
+++ Jifty-DBI/trunk/t/06filter_datetime.t Wed Oct 5 00:12:53 2005
@@ -55,21 +55,9 @@
}
package TestApp::User;
-
use base qw/Jifty::DBI::Record/;
-sub schema {
-
- {
-
- id => { TYPE => 'int(11)' },
- created => { TYPE => 'datetime',
- input_filters => 'Jifty::DBI::Filter::DateTime',
- },
-
- }
-
-}
+1;
sub schema_sqlite {
@@ -104,5 +92,16 @@
}
+package TestApp::User::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+
+ column created =>
+ type is 'datetime',
+ input_filters are qw/Jifty::DBI::Filter::DateTime/;
+}
+
+1;
+
1;
Modified: Jifty-DBI/trunk/t/06filter_truncate.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_truncate.t (original)
+++ Jifty-DBI/trunk/t/06filter_truncate.t Wed Oct 5 00:12:53 2005
@@ -70,23 +70,8 @@
}
package TestApp::User;
-
use base qw/Jifty::DBI::Record/;
-sub schema {
-
- {
-
- id => { TYPE => 'int(11)' },
-# special small lengths to test truncation
- login => { TYPE => 'varchar(5)', DEFAULT => ''},
- name => { TYPE => 'varchar(10)', length => 10, DEFAULT => ''},
- disabled => { TYPE => 'int(4)', length => 4, DEFAULT => 0},
-
- }
-
-}
-
sub schema_sqlite {
<<EOF;
@@ -143,3 +128,24 @@
1;
+package TestApp::User::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+
+ # special small lengths to test truncation
+ column login =>
+ type is 'varchar(5)',
+ default is '';
+
+ column name =>
+ type is 'varchar(10)',
+ length is 10,
+ default is '';
+
+ column disabled =>
+ type is 'int(4)',
+ length is 4,
+ default is 0;
+}
+
+1;
Modified: Jifty-DBI/trunk/t/06filter_utf8.t
==============================================================================
--- Jifty-DBI/trunk/t/06filter_utf8.t (original)
+++ Jifty-DBI/trunk/t/06filter_utf8.t Wed Oct 5 00:12:53 2005
@@ -86,21 +86,8 @@
}
package TestApp::User;
-
use base qw/Jifty::DBI::Record/;
-sub schema {
-
- {
-
- id => { TYPE => 'int(11)' },
- name => { TYPE => 'varchar(5)' },
- signature => { TYPE => 'varchar(100)' },
-
- }
-
-}
-
sub schema_sqlite {
<<EOF;
@@ -137,6 +124,12 @@
}
-1;
+package TestApp::User::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+ column name => type is 'varchar(5)';
+ column signature => type is 'varchar(100)';
+}
+1;
Modified: Jifty-DBI/trunk/t/11schema_records.t
==============================================================================
--- Jifty-DBI/trunk/t/11schema_records.t (original)
+++ Jifty-DBI/trunk/t/11schema_records.t Wed Oct 5 00:12:53 2005
@@ -237,40 +237,18 @@
}
package TestApp::Employee;
-
use base qw/Jifty::DBI::Record/;
-
-sub schema {
- return {
- name => { TYPE => 'varchar' },
- phones => { REFERENCES => 'TestApp::PhoneCollection', KEY => 'employee' }
- };
-}
-
sub _value {
my $self = shift;
my $x = ($self->__value(@_));
return $x;
}
-
-1;
-
package TestApp::Phone;
-
use base qw/Jifty::DBI::Record/;
-
-sub schema {
- return {
- employee => { REFERENCES => 'TestApp::Employee' },
- phone => { TYPE => 'varchar' },
- }
-}
-
package TestApp::PhoneCollection;
-
use base qw/Jifty::DBI::Collection/;
sub table {
@@ -279,11 +257,19 @@
return $tab;
}
-sub new_item {
- my $self = shift;
- my $class = 'TestApp::Phone';
- return $class->new( $self->_handle );
+package TestApp::Phone::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+ column employee => refers_to TestApp::Employee;
+ column phone => type 'varchar';
+}
+
+package TestApp::Employee::Schema;
+BEGIN {
+ use Jifty::DBI::Schema;
+ column name => type 'varchar';
+ column phones => refers_to TestApp::PhoneCollection by 'employee';
}
Modified: Jifty-DBI/trunk/t/testmodels.pl
==============================================================================
--- Jifty-DBI/trunk/t/testmodels.pl (original)
+++ Jifty-DBI/trunk/t/testmodels.pl Wed Oct 5 00:12:53 2005
@@ -1,30 +1,26 @@
-package Sample::Address;
-
+package Sample::Employee;
use base qw/Jifty::DBI::Record/;
-# Class and instance method
+package Sample::Employee::Schema;
+use Jifty::DBI::Schema;
+column name => type is 'varchar';
+column dexterity => type is 'integer';
-# Class and instance method
-sub schema {
- return {
- name => { TYPE => 'varchar', DEFAULT => 'Frank', },
- phone => { TYPE => 'varchar', },
- employee_id => { REFERENCES => 'Sample::Employee', },
- }
-}
-
-package Sample::Employee;
+package Sample::Address;
use base qw/Jifty::DBI::Record/;
+package Sample::Address::Schema;
+use Jifty::DBI::Schema;
+
+column name =>
+ type is 'varchar',
+ default is 'Frank';
-sub schema {
- return {
- name => { TYPE => 'varchar', },
- dexterity => { TYPE => 'integer', },
- }
-}
+column phone =>
+ type is 'varchar';
-1;
+column employee_id =>
+ refers_to Sample::Employee;
More information about the Rt-commit
mailing list