From 49294d48ec6e3994c4eaac1880c6aab9bfc57f5b Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@cervoi.se> Date: Tue, 17 Feb 2015 13:38:58 +0100 Subject: [PATCH] new area: ORM introduction --- Sam/Calendar.pm | 25 +++++++++++++++++++++++++ Sam/Chan.pm | 27 +++++++++++++++++++++++++++ Sam/DB.pm.sample | 13 +++++++++++++ Sam/DB/Object.pm | 8 ++++++++ Sam/Event.pm | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+) create mode 100644 Sam/Calendar.pm create mode 100644 Sam/Chan.pm create mode 100644 Sam/DB.pm.sample create mode 100644 Sam/DB/Object.pm create mode 100644 Sam/Event.pm diff --git a/Sam/Calendar.pm b/Sam/Calendar.pm new file mode 100644 index 0000000..e48815a --- /dev/null +++ b/Sam/Calendar.pm @@ -0,0 +1,25 @@ +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; diff --git a/Sam/Chan.pm b/Sam/Chan.pm new file mode 100644 index 0000000..268a2aa --- /dev/null +++ b/Sam/Chan.pm @@ -0,0 +1,27 @@ +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; diff --git a/Sam/DB.pm.sample b/Sam/DB.pm.sample new file mode 100644 index 0000000..6804ed2 --- /dev/null +++ b/Sam/DB.pm.sample @@ -0,0 +1,13 @@ +package Sam::DB; + +use base qw(Rose::DB); + +__PACKAGE__->use_private_registry; + +__PACKAGE__->register_db( + driver => 'mysql', + database => '', + host => '', + username => '', + password => '', +); diff --git a/Sam/DB/Object.pm b/Sam/DB/Object.pm new file mode 100644 index 0000000..f12def1 --- /dev/null +++ b/Sam/DB/Object.pm @@ -0,0 +1,8 @@ +package Sam::DB::Object; + +use Sam::DB; +use base qw(Rose::DB::Object); + +sub init_db { Sam::DB->new } + +1; diff --git a/Sam/Event.pm b/Sam/Event.pm new file mode 100644 index 0000000..3df9089 --- /dev/null +++ b/Sam/Event.pm @@ -0,0 +1,32 @@ +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; -- GitLab