NAME
Teng::Schema::Declare - DSL For Declaring Teng Schema
NORMAL USE
package
MyDB::Schema;
use
strict;
use
warnings;
table {
name
"your_table_name"
;
pk
"primary_key"
;
columns
qw( col1 col2 col3 )
;
inflate
'col1'
=>
sub
{
my
(
$col_value
) =
@_
;
return
MyDB::Class->new(
name
=>
$col_value
);
};
deflate
'col1'
=>
sub
{
my
(
$col_value
) =
@_
;
return
ref
$col_value
?
$col_value
->name :
$col_value
;
};
row_class
'MyDB::Row'
;
# optional
};
INLINE DECLARATION
my
$schema
= schema {
table {
name
"your_table_name"
;
columns
qw( col1 col2 col3 )
;
};
}
"MyDB::Schema"
;
METHODS
schema
-
schema data creation wrapper.
table
-
set table name
pk
-
set primary key
columns
-
set columns
inflate_rule
-
set inflate rule
row_namespace
-
create Row class namespace
base_row_class
-
Specify the default base row class with Teng::Schema::Declare.
Default value is Teng::Row.
This option is useful when you adds features for My::DB::Row class.
default_row_class_prefix
-
Specify the default prefix of row class.
row_class
of each table definition has priority overdefault_row_class_prefix
.e.g.:
my
$schema
= schema {
default_row_class_prefix
'My::Entity'
;
table {
name
'user'
;
column
qw(name)
;
};
};
$schema
->get_row_class(
'user'
);
# => My::Entity::User
Default value is determined by the schema class.
e.g.:
package
My::DB::Schema;
table {
name
'user'
;
column
qw(name)
;
};
__PACKAGE__->instance->get_row_class(
'user'
);
# => My::DB::Row::User
1;