/[Frey]/trunk/lib/Strix/Schema.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Strix/Schema.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide annotations)
Mon Jun 30 07:12:56 2008 UTC (15 years, 9 months ago) by dpavlin
File size: 765 byte(s)
create unique schema cache for dsn
1 dpavlin 2 package Strix::Schema;
2    
3     use Fey::DBIManager;
4     use Fey::DBIManager::Source;
5     use Fey::Loader;
6     use Fey::ORM::Schema;
7    
8 dpavlin 15 use Storable;
9     use Data::Dump qw/dump/;
10 dpavlin 35 use URI::Escape;
11 dpavlin 15
12 dpavlin 35 my $dsn = 'dbi:Pg:dbname=new';
13     $dsn = 'dbi:SQLite:dbname=./var/strix.sqlite';
14 dpavlin 15
15 dpavlin 35 my $schema_file = 'var/schema.' . uri_escape( $dsn );
16 dpavlin 2
17 dpavlin 35 warn "Database $dsn schema cache $schema_file\n";
18    
19     my $source = Fey::DBIManager::Source->new( dsn => $dsn );
20    
21 dpavlin 15 my $schema;
22     if ( -e $schema_file ) {
23     $schema = retrieve $schema_file or die "can't read schema from $schema_file: $!";
24     } else {
25     $schema= Fey::Loader->new( dbh => $source->dbh() )->make_schema();
26     store $schema, $schema_file or warn "can't store schema into $schema_file: $!";
27     }
28 dpavlin 2
29     has_schema $schema;
30    
31     __PACKAGE__->DBIManager()->add_source($source);

  ViewVC Help
Powered by ViewVC 1.1.26