SQL::Tr...er::DBI(3)

🌸 NAME 🌸

okay bestie, welcome to SQL::Tr...er::DBI(3) πŸ’… β€” it's a User Contributed Perl Documentation page for SQL::Translator::Parser::DBI, aka the β€œparser” for DBI handles. no cap, that's the whole assignment. 🫢

✨ SYNOPSIS ✨

so first flavor: you already have an open $dbh and you're ready to go:

use DBI;
use SQL::Translator;

my $dbh = DBI->connect('dsn', 'user', 'pass',
    {
        RaiseError       => 1,
        FetchHashKeyName => 'NAME_lc',
    }
);

my $translator  =  SQL::Translator->new(
    parser      => 'DBI',
    parser_args => {
        dbh => $dbh,
    },
);

Or:

use SQL::Translator;

my $translator      =  SQL::Translator->new(
    parser          => 'DBI',
    parser_args     => {
        dsn         => 'dbi:mysql:FOO',
        db_user     => 'guest',
        db_password => 'password',
  }
);

🌈 DESCRIPTION 🌈

okay so this parser accepts an open database handle (or the arguments to create one) and queries the database directly for the information. direct-query energy, literally. πŸ”₯

The following are acceptable arguments:

  • dbh β€” an open DBI database handle. NB: Be sure to create the database with the FetchHashKeyName => 'NAME_lc' option as all the DBI parsers expect lowercased column names.
  • dsn β€” the DSN to use for connecting to a database.
  • db_user β€” the user name to use for connecting to a database.
  • db_password β€” the password to use for connecting to a database.

There is no need to specify which type of database you are querying as this is determined automatically by inspecting $dbh->{'Driver'}{'Name'}. the code just knows, iykyk. If a parser exists for your database, it will be used automatically; if not, the code will fail automatically (and you can write the parser and contribute it to the project!). 🫑

Currently parsers exist for the following databases:

  • MySQL 🐬
  • SQLite πŸͺΆ
  • Sybase 🧚
  • PostgreSQL (still experimental) πŸ§ͺ

Most of these parsers are able to query the database directly for the structure rather than parsing a text file. For large schemas, this is probably orders of magnitude faster than traditional parsing (which uses Parse::RecDescent, an amazing module but really quite slow). big schema? this is your moment ⭐

Though no Oracle parser currently exists, it would be fairly easy to query an Oracle database directly by using DDL::Oracle to generate a DDL for the schema and then using the normal Oracle parser on this. Perhaps future versions of SQL::Translator will include the ability to query Oracle directly and skip the parsing of a text file, too. future goals, manifesting it πŸ¦‹

🫢 AUTHOR 🫢

Ken Y. Clark <kclark@cpan.org>. iconic. πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

DBI, SQL::Translator. go read those bestie, fr fr. πŸ“š


made with πŸ’– by perl v5.42.0 on 2024-12-12 β€” SQL::Tr...er::DBI(3) out! 🫢✨

πŸ“¦ where this page comes from