in Mojo::SQLite, some transactions doesn't seem to be immediately committed to the database. I wonder if this is related to SQLite
or how I have defined Mojo::SQLite (I am afraid it is the latter :( ). This is the logic I have followed:
package GestioMaster::Obj::DB;
use Mojo::Base -base;
use Mojo::SQLite;
use GestioMaster::Model::DB;
has sqlite => sub { Mojo::SQLite->new('sqlite:db/master.db') };
has model => sub {
my $self = shift;
return GestioMaster::Model::DB->new( sqlite => $self->sqlite );
};
package GestioMaster;
use Mojo::Base 'Mojolicious';
use GestioMaster::Obj::DB;
sub startup {
my $self = shift;
my $config = $self->plugin('Config');
$self->helper( model => sub {
state $model = GestioMaster::Obj::DB->new->model;
});
...
--> Accessing the database is defined in the
Model:
package GestioMaster::Model::DB;
use Mojo::Base -base;
has 'sqlite';
...
sub un_modul {
my ($self, $modul) = @_;
return $self->sqlite->db->select('moduls',undef,{ modul => $modul})->hash;
}
...
package GestioMaster::Obj::Modul;
use Mojo::Base -base;
# Object that makes database available
use GestioMaster::Obj::DB;
has _model => sub { GestioMaster::Obj::DB->new->model };
has modul => "";
has un_modul => sub {
my $self = shift;
return $self->_model->un_modul( $self->modul );
};
has ident => sub { shift->un_modul->{'ident'} };
has coord => sub { shift->un_modul->{'coord'} };
has nom_modul => sub { shift->un_modul->{'nom_modul'}; };
...
package GestioMaster::Controller::Moduls::Modul;
use Mojo::Base -base;
use GestioMaster::Obj::Modul;
has moduls => sub {
my $self = shift;
my @moduls = qw/M1 M2a M2b M3a M3b M3d M3e M4 M5a M5b M5c M5d M6/;
my $mod_obj = [];
foreach my $mod ( @moduls ) {
push @{$mod_obj}, GestioMaster::Obj::Modul->new( modul => $mod );
}
return $mod_obj;
};
package GestioMaster::Controller::Public;
use GestioMaster::Controller::Moduls::Modul;
state $moduls = GestioMaster::Controller::Moduls::Modul->new->moduls;
sub inici { shift->render( moduls => $moduls ) }
% foreach my $mod ( @{ $moduls } ) {
<li><a href="<%= '/pub/modul/' . $mod->modul %>"><%= $mod->modul . ": " . $mod->nom_modul %></a></li>
% }
So far so good, till the application started to write to the database and noticed some transactions were not immediately committed :O
My questions:
a) Opening the database in two different modules has an effect on how transactions are committed?
c) If the application has to be rewritten, how can the database defined in package GestioMaster be accessed from GestioMaster::Obj::Modul?
Thanks!