move all mysql- and Pg-specific code to DBD driver callbacks
[DBIx-DBSchema.git] / DBSchema / DBD.pm
index 019b3b1..be08320 100644 (file)
@@ -3,7 +3,7 @@ package DBIx::DBSchema::DBD;
 use strict;
 use vars qw($VERSION);
 
-$VERSION = '0.03';
+$VERSION = '0.05';
 
 =head1 NAME
 
@@ -14,7 +14,7 @@ DBIx::DBSchema::DBD - DBIx::DBSchema Driver Writer's Guide and Base Class
   perldoc DBIx::DBSchema::DBD
 
   package DBIx::DBSchema::DBD::FooBase
-  use DBIx::DBSchmea::DBD;
+  use DBIx::DBSchema::DBD;
   @ISA = qw(DBIx::DBSchema::DBD);
 
 =head1 DESCRIPTION
@@ -55,17 +55,84 @@ table.
 
 =item unique CLASS DBI_DBH TABLE
 
+Deprecated method - see the B<indices> method for new drivers.
+
 Given an active DBI database handle, return a hashref of unique indices.  The
 keys of the hashref are index names, and the values are arrayrefs which point
 a list of column names for each.  See L<perldsc/"HASHES OF LISTS"> and
-L<DBIx::DBSchema::ColGroup>.
+L<DBIx::DBSchema::Index>.
 
 =item index CLASS DBI_DBH TABLE
 
+Deprecated method - see the B<indices> method for new drivers.
+
 Given an active DBI database handle, return a hashref of (non-unique) indices.
 The keys of the hashref are index names, and the values are arrayrefs which
 point a list of column names for each.  See L<perldsc/"HASHES OF LISTS"> and
-L<DBIx::DBSchema::ColGroup>.
+L<DBIx::DBSchema::Index>.
+
+=item indices CLASS DBI_DBH TABLE
+
+Given an active DBI database handle, return a hashref of all indices, both
+unique and non-unique.  The keys of the hashref are index names, and the values
+are again hashrefs with the following keys:
+
+=over 8
+
+=item name - Index name (redundant)
+
+=item using - Optional index method
+
+=item unique - Boolean indicating whether or not this is a unique index
+
+=item columns - List reference of column names (or expressions)
+
+=back
+
+(See L<FS::DBIx::DBSchema::Index>)
+
+New drivers are advised to implement this method, and existing drivers are
+advised to (eventually) provide this method instead of B<index> and B<unique>.
+
+For backwards-compatibility with current drivers, the base DBIx::DBSchema::DBD
+class provides an B<indices> method which uses the old B<index> and B<unique>
+methods to provide this data.
+
+=cut
+
+sub indices {
+  #my($proto, $dbh, $table) = @_;
+  my($proto, @param) = @_;
+
+  my $unique_hr = $proto->unique( @param );
+  my $index_hr  = $proto->index(  @param );
+
+  scalar(
+    {
+  
+      (
+        map {
+              $_ => { 'name'    => $_,
+                      'unique'  => 1,
+                      'columns' => $unique_hr->{$_},
+                    },
+            }
+            keys %$unique_hr
+      ),
+  
+      (
+        map {
+              $_ => { 'name'    => $_,
+                      'unique'  => 0,
+                      'columns' => $index_hr->{$_},
+                    },
+            }
+            keys %$index_hr
+      ),
+  
+    }
+  );
+}
 
 =item default_db_catalog
 
@@ -76,7 +143,7 @@ Inheriting from DBIx::DBSchema::DBD will provide the default empty string.
 
 sub default_db_catalog { ''; }
 
-=item default_db_catalog
+=item default_db_schema
 
 Returns the default database schema for the DBI table_info command.
 Inheriting from DBIx::DBSchema::DBD will provide the default empty string.
@@ -85,6 +152,60 @@ Inheriting from DBIx::DBSchema::DBD will provide the default empty string.
 
 sub default_db_schema { ''; }
 
+=item column_callback DBH TABLE_NAME COLUMN_OBJ
+
+Optional callback for driver-specific overrides to SQL column definitions.
+
+Should return a hash reference, empty for no action, or with one or more of
+the following keys defined:
+
+effective_type - Optional type override used during column creation.
+
+explicit_null - Set true to have the column definition declare NULL columns explicitly
+
+effective_default - Optional default override used during column creation.
+
+effective_local - Optional local override used during column creation.
+
+
+=cut
+
+sub column_callback { {}; }
+
+=item add_column_callback DBH TABLE_NAME COLUMN_OBJ
+
+Optional callback for additional SQL statments to be called when adding columns
+to an existing table.
+
+Should return a hash reference, empty for no action, or with one or more of
+the following keys defined:
+
+effective_type - Optional type override used during column creation.
+
+effective_null - Optional nullability override used during column creation.
+
+sql_after - Array reference of SQL statements to be executed after the column is added.
+
+=cut
+
+sub add_column_callback { {}; }
+
+=item alter_column_callback DBH TABLE_NAME OLD_COLUMN_OBJ NEW_COLUMN_OBJ
+
+Optional callback for overriding the SQL statments to be called when altering
+columns to an existing table.
+
+Should return a hash reference, empty for no action, or with one or more of
+the following keys defined:
+
+sql_alter_null - Alter SQL statment for changing nullability to be used instead of the default
+
+=cut
+
+sub alter_column_callback { {}; }
+
+=cut
+
 =back
 
 =head1 TYPE MAPPING
@@ -112,6 +233,7 @@ Ivan Kohler <ivan-dbix-dbschema@420.am>
 =head1 COPYRIGHT
 
 Copyright (c) 2000-2005 Ivan Kohler
+Copyright (c) 2007 Freeside Internet Services, Inc.
 All rights reserved.
 This program is free software; you can redistribute it and/or modify it under
 the same terms as Perl itself.
@@ -121,7 +243,7 @@ the same terms as Perl itself.
 =head1 SEE ALSO
 
 L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD::mysql>, L<DBIx::DBSchema::DBD::Pg>,
-L<DBIx::DBSchema::ColGroup>, L<DBI>, L<DBI::DBD>, L<perllol>,
+L<DBIx::DBSchema::Index>, L<DBI>, L<DBI::DBD>, L<perllol>,
 L<perldsc/"HASHES OF LISTS">
 
 =cut