Skip to content
Extraits de code Groupes Projets
Valider 49294d48 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

new area: ORM introduction

parent 49cbfec3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package Sam::Calendar;
use base qw(Sam::DB::Object);
__PACKAGE__->meta->setup
(
table => 'sam_calendars',
auto => 1,
);
__PACKAGE__->meta->setup
(
table => 'sam_calendars',
columns =>
[
id => { type => 'integer', not_null => 1 },
open => { type => 'boolean', not_null => 1, default => 0},
name => { type => 'varchar', length => 20, not_null => 1 },
],
primary_key_columns => [ 'id' ],
);
1;
package Sam::Chan;
use base qw(Sam::DB::Object);
__PACKAGE__->meta->setup
(
table => 'sam_channels',
columns =>
[
calendar_id => { type => 'integer', not_null => 1 },
name => { type => 'varchar', length => 20, not_null => 1 },
],
primary_key_columns => [ 'name' ],
foreign_keys =>
[
calendar =>
{
class => 'Sam::Calendar',
key_columns => { calendar_id => 'id' },
},
],
);
1;
package Sam::DB;
use base qw(Rose::DB);
__PACKAGE__->use_private_registry;
__PACKAGE__->register_db(
driver => 'mysql',
database => '',
host => '',
username => '',
password => '',
);
package Sam::DB::Object;
use Sam::DB;
use base qw(Rose::DB::Object);
sub init_db { Sam::DB->new }
1;
package Sam::Event;
use base qw(Sam::DB::Object);
__PACKAGE__->meta->setup
(
table => 'sam',
columns =>
[
id => { type => 'integer', not_null => 1 },
title => { type => 'varchar', length => 255, not_null => 1 },
date => { type => 'timestamp', not_null => 1 },
place => { type => 'varchar', length => 255 },
description => { type => 'varchar', length => 500 },
link => { type => 'varchar', length => 1000 },
calendar_id => { type => 'integer', not_null => 1 },
],
primary_key_columns => [ 'id' ],
foreign_keys =>
[
calendar =>
{
class => 'Sam::Calendar',
key_columns => { calendar_id => 'id' },
},
],
);
1;
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter