DBSchema::DBD(3pm)
π DBIx::DBSchema::DBD β the Driver Writer's Guide (aka the base class, aka where the magic starts) π
okay bestie, pull up a chair, because this is User Contributed Perl Documentation's finest, and it's literally the driver writer's guide and the base class for DBIx::DBSchema::DBD. it's giving "read this before you write a driver" energy, and honestly? iconic. π
β¨ SYNOPSIS β¨
so basically, if you ever need the docs again, you just go:
perldoc DBIx::DBSchema::DBD
and if you're out here building your very own driver, the vibe is:
package DBIx::DBSchema::DBD::FooBase
use DBIx::DBSchema::DBD;
@ISA = qw(DBIx::DBSchema::DBD);
like, you inherit from it, you become it, main character energy fr fr. π¦
πΈ DESCRIPTION πΈ
okay so here's the tea, and it's important tea:
your driver should be named DBIx::DBSchema::DBD::DatabaseName, where DatabaseName is literally the same as the DBD:: driver for this database. no notes, that's just the rule. π
and drivers should implement the following class methods, bestie. this is the whole to-do list. do not skip any. the way that each one mattersβ¦ π₯
columns CLASS DBI_DBH TABLEβ you hand it an active DBI database handle, and it gives you back a listref of listrefs (peepperllolif that's new to you). each inner listref has six elements, in this exact order: column name, column type, nullability, column length, column default, and then a field reserved for driver-specific use. six. count them. π«Άcolumn CLASS DBI_DBH TABLE COLUMNβ same ascolumnsabove, except it returns the listref for a single column. and guess what, you can just inherit fromDBIx::DBSchema::DBDto get this function for free. slay, free stuff. πprimary_key CLASS DBI_DBH TABLEβ give it an active DBI database handle and it returns the primary key for the specified table. simple as that. πunique CLASS DBI_DBH TABLEβ β οΈ deprecated method, bestie β for new drivers you want theindicesmethod instead. but okay, the lore: given an active DBI database handle, it returns 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"HASHES OF LISTS"inperldscandDBIx::DBSchema::Index. πindex CLASS DBI_DBH TABLEβ also β οΈ deprecated, same deal,indicesis the new one for new drivers. given an active DBI database handle, it returns a hashref of (non-unique) indices. keys are index names, values are arrayrefs pointing to a list of column names for each. see"HASHES OF LISTS"inperldscandDBIx::DBSchema::Index. πindices CLASS DBI_DBH TABLEβ β¨ the new hotness. given an active DBI database handle, returns 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 these keys:nameβ index name (yes it's redundant, we know, it's just there)usingβ optional index methoduniqueβ boolean indicating whether or not this is a unique indexcolumnsβ list reference of column names (or expressions)
(see FS::DBIx::DBSchema::Index)
new drivers, you are advised to implement this method. existing drivers, you are advised to (eventually) provide this method instead of index and unique. no pressure but likeβ¦ some pressure. π
and for backwards-compatibility with current drivers, the base DBIx::DBSchema::DBD class provides an indices method which uses the old index and unique methods to provide this data. so it's got you, bestie. π«Ά
default_db_catalogβ returns the default database catalog for the DBItable_infocommand. inheriting fromDBIx::DBSchema::DBDwill provide the default empty string. easy win. βdefault_db_schemaβ returns the default database schema for the DBItable_infocommand. inheriting fromDBIx::DBSchema::DBDwill provide the default empty string. same energy, still a win. βconstraints CLASS DBI_DBH TABLEβ given an active DBI database handle, returns the constraints (currently, foreign keys) for the specified table, as a list of hash references. π
each hash reference has the following keys:
constraintβ contraint name (spelled exactly like that in the source, keeping it)columnsβ list refrence of column names (also kept as-is, we don't fix typos around here, we preserve them)tableβ foreign taable name (yep, also exactly as written)referencesβ list reference of column names in foreign tablematchβ (no description given)on_deleteβ (no description given)on_updateβ (no description given)
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 declareNULLcolumns explicitlyeffective_defaultβ optional default override used during column creation.effective_localβ optional local override used during column creation.
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.
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β alter SQL statement(s) for changing everything about a column. specifying this overrides processing of individual changes (type, nullability, default, etc.). like, it takes over the whole thing, so heads up.sql_alter_typeβ alter SQL statement(s) for changing type and length (there is no default).sql_alter_nullβ alter SQL statement(s) for changing nullability to be used instead of the default.
column_value_needs_quoting COLUMN_OBJβ optional callback for determining if a column's default value require quoting. returns true if it does, false otherwise. short king of a method. π
π¦ TYPE MAPPING π¦
okay so this part is actually so clever. you can define a %typemap array for your driver to map "standard" data types to database-specific types. πΈ
for example, the MySQL TIMESTAMP field has non-standard auto-updating semantics; the MySQL DATETIME type is what other databases and the ODBC standard call TIMESTAMP, so one of the entries in the MySQL %typemap is:
'TIMESTAMP' => 'DATETIME',
another example is the Pg %typemap which maps the standard types BLOB and LONG VARBINARY to the Pg-specific BYTEA:
'BLOB' => 'BYTEA',
'LONG VARBINARY' => 'BYTEA',
make sure you use all uppercase-keys. π like, literally, uppercase keys only, that's the vibe check.
π AUTHOR π
Ivan Kohler <ivan-dbix-dbschema@420.am>
π COPYRIGHT π
Copyright (c) 2000-2005 Ivan Kohler Copyright (c) 2007-2017 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.
π BUGS π
(no bugs listed β honestly a flex)
π SEE ALSO π
DBIx::DBSchemaDBIx::DBSchema::DBD::mysqlDBIx::DBSchema::DBD::PgDBIx::DBSchema::IndexDBIDBI::DBDperllol"HASHES OF LISTS"inperldsc
okay and that's the whole page, bestie, you ate it. this was documented by the perl gang, v5.36.0, dated 2022-09-10, and the manual page itself is DBSchema::DBD(3pm). xoxo, go write that driver. π«Άβ¨π
π¦ where this page comes from
- ubuntu noble: libdbix-dbschema-perl 0.47-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-dbschema-perl 0.47-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-dbschema-perl 0.47-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms