From 4f2a8ea0419ee4f725cb05b8cbd06410a61b5d29 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Sep 2000 12:40:35 +0000 Subject: [PATCH] implement pretty_read --- DBSchema.pm | 30 ++++++++++++++++++++++++++++-- DBSchema/Table.pm | 2 +- README | 4 ++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/DBSchema.pm b/DBSchema.pm index ae82a9b..da182cd 100644 --- a/DBSchema.pm +++ b/DBSchema.pm @@ -7,6 +7,9 @@ use vars qw(@ISA $VERSION); use DBI; use FreezeThaw qw(freeze thaw cmpStr); use DBIx::DBSchema::Table; +use DBIx::DBSchema::Column; +use DBIx::DBSchema::ColGroup::Unique; +use DBIx::DBSchema::ColGroup::Index; #@ISA = qw(Exporter); @ISA = (); @@ -47,6 +50,16 @@ DBIx::DBSchema - Database-independent schema objects DBIx::DBSchema objects are collections of DBIx::DBSchema::Table objects and represent a database schema. +This module implements an OO-interface to database schemas. Using this module, +you can create a database schema with an OO Perl interface. You can read the +schema from an existing database. You can save the schema to disk and restore +it a different process. Most importantly, DBIx::DBSchema can write SQL +CREATE statements statements for different databases from a single source. + +Currently supported databases are MySQL and PostgreSQL. DBIx::DBSchema will +attempt to use generic SQL syntax for other databases. Assistance adding +support for other databases is welcomed. + =head1 METHODS =over 4 @@ -246,8 +259,21 @@ B method. =cut sub pretty_read { - die "unimplemented (pull from fs-setup)"; - my($proto) = @_; + my($proto, $href) = @_; + my $schema = proto->new( map { + my(@columns); + while (@{$tables{$_}{'columns'}}) { + my($name,$type,$null,$length)=splice @{$tables{$_}{'columns'}}, 0, 4; + push @columns, new DBIx::DBSchema::Column ( $name,$type,$null,$length ); + } + DBIx::DBSchema::Table->new( + $_, + $tables{$_}{'primary_key'}, + DBIx::DBSchema::ColGroup::Unique->new($tables{$_}{'unique'}), + DBIx::DBSchema::ColGroup::Index->new($tables{$_}{'index'}), + @columns, + ); + } (keys %tables) ); } # private subroutines diff --git a/DBSchema/Table.pm b/DBSchema/Table.pm index a05becf..47e0b12 100644 --- a/DBSchema/Table.pm +++ b/DBSchema/Table.pm @@ -284,7 +284,7 @@ supported in the future. sub sql_create_table { my($self,$datasrc)=@_; - + warn $datasrc; my(@columns)=map { $self->column($_)->line($datasrc) } $self->columns; push @columns, "PRIMARY KEY (". $self->primary_key. ")" if $self->primary_key; diff --git a/README b/README index 2d1c2e2..5fb0d66 100644 --- a/README +++ b/README @@ -10,7 +10,7 @@ This module implements an OO-interface to database schemas. Using this module, you can create a database schema with an OO Perl interface. You can read the schema from an existing database. You can save the schema to disk and restore it a different process. Most importantly, DBIx::DBSchema can write SQL -statements to create the given schema. +CREATE statements statements for different databases from a single source. Currently supported databases are MySQL and PostgreSQL. DBIx::DBSchema will attempt to use generic SQL syntax for other databases. Assistance adding @@ -38,4 +38,4 @@ A mailing list is available. Send a blank message to Homepage: -$Id: README,v 1.2 2000-09-27 11:51:36 ivan Exp $ +$Id: README,v 1.3 2000-09-27 12:40:35 ivan Exp $ -- 2.20.1