Directory and File Structure: Best Practice for SQLite?

73 views
Skip to first unread message

Tom Browder

unread,
Oct 7, 2012, 6:22:48 PM10/7/12
to rose-db...@googlegroups.com
I'm certainly not an expert, but I am looking forward to using
Rose::DB for my SQLite databases with hopes of using PostgreSQL
instead later.

In the more complex examples it is not clear to me the exact file layout.

My question is, what is the best way to do the following:

1. use 2 or more separate database files (dbf), each for a fairly
different purpose (they would be separate databases in Pg)

2. each dbf has one table

As I read the docs I think can do something like the following:

directory structure:

My/
DB/

file structure

./DB1.pm
package DB1;
use My::DB;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->setup(
table => 'db1',
columns => [ qw(id data) ],
unique_key => 'id',
);
sub init_db { My::DB->new('db1') }
__PACKAGE__->meta->make_manager_class('db1');
1;

./DB2.pm
use My::DB;
use base qw(Rose::DB::Object);
__PACKAGE__->meta->setup(
table => 'db2',
columns => [ qw(id data) ],
unique_key => 'id',
);
sub init_db { My::DB->new('db2') }
__PACKAGE__->meta->make_manager_class('db2');
1;

My/DB/DB.pm
package My::DB;
use Rose::DB;
our @ISA = qw(Rose::DB);
# Use a private registry for this class
__PACKAGE__->use_private_registry;
# NO defaults for multiple types
__PACKAGE__->register_db(
type => 'db1',
driver => 'sqlite', # all below use this
database => 'db1',
);
__PACKAGE__->register_db(
type => 'db2',
database => 'db2',
);
# etc.
1;

Use the databases:

my $db1ref = DB1::Manager->get_db1();
foreach my $r (@$db1ref) {
print $r->id, "\n";
print $r->data, "\n";
}
# etc.

Comments?

I'm starting coding anyway to see what happens.

Best regards,

-Tom
Reply all
Reply to author
Forward
0 new messages