Package Info

perl-SQL-Abstract


Generate SQL from Perl data structures


Unspecified

This module was inspired by the excellent DBIx::Abstract. However, in using that module I found that what I really wanted to do was generate SQL, but still retain complete control over my statement handles and use the DBI interface. So, I set out to create an abstract SQL generation module.

While based on the concepts used by DBIx::Abstract, there are several important differences, especially when it comes to WHERE clauses. I have modified the concepts used to make the SQL easier to generate from Perl data structures and, IMO, more intuitive. The underlying idea is for this module to do what you mean, based on the data structures you provide it. The big advantage is that you don't have to modify your code every time your data changes, as this module figures it out.

To begin with, an SQL INSERT is as easy as just specifying a hash of 'key=value' pairs:

my %data = (
    name => 'Jimbo Bobson',
    phone => '123-456-7890',
    address => '42 Sister Lane',
    city => 'St. Louis',
    state => 'Louisiana',
);

The SQL can then be generated with this:

my($stmt, @bind) = $sql->insert('people', \%data);

Which would give you something like this:

$stmt = "INSERT INTO people
                (address, city, name, phone, state)
                VALUES (?, ?, ?, ?, ?)";
@bind = ('42 Sister Lane', 'St. Louis', 'Jimbo Bobson',
         '123-456-7890', 'Louisiana');

These are then used directly in your DBI code:

my $sth = $dbh->prepare($stmt);
$sth->execute(@bind);

License: Artistic-1.0 OR GPL-1.0-or-later
URL: https://metacpan.org/release/SQL-Abstract

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
2.000001-bp156.3.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
2.000001-bp155.2.8 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
2.000001-bp154.1.13 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
1.85-bp153.1.16 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
1.85-bp152.3.17 info GA Release 2020-04-17 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
1.85-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
1.85-bp151.2.13 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract
1.85-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-SQL-Abstract