summaryrefslogtreecommitdiff
path: root/GroLUG
diff options
context:
space:
mode:
Diffstat (limited to 'GroLUG')
-rw-r--r--GroLUG/lib/GroLUG/M/DB.pm6
-rw-r--r--GroLUG/lib/GroLUG/M/DB/Iscritto.pm10
-rw-r--r--GroLUG/lib/GroLUG/M/DB/Pagamento.pm20
-rw-r--r--GroLUG/t/m_DB.t1
-rw-r--r--GroLUG/test_manuali/prova_db.pl25
5 files changed, 59 insertions, 3 deletions
diff --git a/GroLUG/lib/GroLUG/M/DB.pm b/GroLUG/lib/GroLUG/M/DB.pm
index e45de9e..193cb7a 100644
--- a/GroLUG/lib/GroLUG/M/DB.pm
+++ b/GroLUG/lib/GroLUG/M/DB.pm
@@ -4,14 +4,14 @@ use strict;
use base 'Catalyst::Model::DBIC::Plain';
my @conn_info = (
- '',
- '',
+ 'dbi:Pg:dbname=iscritti',
+ 'grolug',
'',
{ RaiseError => 1, PrintError => 0, ShowErrorStatement => 1, TraceLevel => 0 }
);
__PACKAGE__->load_classes;
-__PACKAGE__->compose_connection( __PACKAGE__, @conn_info );
+#DBIx::Class::Schema->compose_connection( __PACKAGE__, @conn_info );
=head1 NAME
diff --git a/GroLUG/lib/GroLUG/M/DB/Iscritto.pm b/GroLUG/lib/GroLUG/M/DB/Iscritto.pm
new file mode 100644
index 0000000..32282f5
--- /dev/null
+++ b/GroLUG/lib/GroLUG/M/DB/Iscritto.pm
@@ -0,0 +1,10 @@
+package GroLUG::M::DB::Iscritto;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->load_components(qw(PK::Auto::Pg));
+__PACKAGE__->table('iscritti');
+__PACKAGE__->add_columns(qw(id nome email note));
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->has_many(pagamenti=>'GroLUG::M::DB::Pagamento','iscritto');
+
+1;
diff --git a/GroLUG/lib/GroLUG/M/DB/Pagamento.pm b/GroLUG/lib/GroLUG/M/DB/Pagamento.pm
new file mode 100644
index 0000000..23ee176
--- /dev/null
+++ b/GroLUG/lib/GroLUG/M/DB/Pagamento.pm
@@ -0,0 +1,20 @@
+package GroLUG::M::DB::Pagamento;
+use base 'DBIx::Class::Core';
+use DateTime::Format::Pg;
+
+__PACKAGE__->load_components(qw(PK::Auto::Pg));
+__PACKAGE__->table('pagamenti');
+__PACKAGE__->add_columns(qw(id iscritto data_pagamento data_iscrizione data_scadenza prezzo));
+__PACKAGE__->set_primary_key('id');
+__PACKAGE__->belongs_to(iscritto=>'GroLUG::M::DB::Iscritto');
+
+for my $col (qw(data_pagamento data_iscrizione data_scadenza)) {
+ __PACKAGE__->inflate_column(
+ $col,
+ {
+ inflate => sub { DateTime::Format::Pg->parse_datetime(shift) },
+ deflate => sub { DateTime::Format::Pg->format_datetime(shift) },
+ });
+}
+
+1;
diff --git a/GroLUG/t/m_DB.t b/GroLUG/t/m_DB.t
index dee8fd0..fcb9aea 100644
--- a/GroLUG/t/m_DB.t
+++ b/GroLUG/t/m_DB.t
@@ -1,3 +1,4 @@
+#!perl
use strict;
use warnings;
diff --git a/GroLUG/test_manuali/prova_db.pl b/GroLUG/test_manuali/prova_db.pl
new file mode 100644
index 0000000..fcfc7bc
--- /dev/null
+++ b/GroLUG/test_manuali/prova_db.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use GroLUG::M::DB;
+use DateTime;
+
+#use Devel::TraceCalls;trace_calls { Package => [qw(DBIx::Class::Schema DBIx::Class::Storage::DBI)]};
+
+my $schema=GroLUG::M::DB->connect('dbi:Pg:dbname=iscritti',
+ 'grolug',
+ '',
+ { RaiseError => 1, PrintError => 0, ShowErrorStatement => 1, TraceLevel => 0 });
+
+my $iscritto=$schema->resultset('GroLUG::M::DB::Iscritto')->create({
+ nome => '__tizio',
+ email => 'tizio@qui',
+});
+
+$iscritto->add_to_pagamenti({
+ data_pagamento=>DateTime->now(),
+ data_iscrizione=>DateTime->now()->subtract(days=>10),
+ data_scadenza=>DateTime->now()->subtract(days=>10)->add(years=>1),
+ prezzo=>50});
+
+$schema->commit();