Skip to content

About

SQL::Abstract

Resources

Security policy

Stars

20 stars

Watchers

7 watching

Forks

Latest commit

 

History

1,127 Commits

Folders and files

Repository files navigation

SQL::Abstract

Generate SQL from Perl data structures.

SQL::Abstract turns Perl hashes and arrays into an SQL statement plus a list of bind values, ready for DBI. Values always end up as bind values, never in the SQL text.

use SQL::Abstract;

my $sql = SQL::Abstract->new;

my ($stmt, @bind) = $sql->select(
  'people',
  [qw(name email)],
  { status => 'active', age => { '>' => 18 } },
  'name',
);
# $stmt: SELECT name, email FROM people WHERE ( age > ? AND status = ? ) ORDER BY name
# @bind: (18, 'active')

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

The same works for insert, update, delete and plain where. See the full documentation on MetaCPAN.

The distribution also contains:

Installation

cpanm SQL::Abstract

From a git checkout:

perl Makefile.PL
make
make test
make install

DBIx::Class and DBIO

DBIx::Class no longer uses this module: since 0.082842 it uses SQL::Abstract::Classic, a frozen copy of the 1.x line.

DBIO, a fork of DBIx::Class, builds its SQL with SQL::Abstract 2.x and uses SQL::Abstract::Tree for its query trace.

Support

Security issues: please do not report them publicly, see SECURITY.md.

License

Copyright (c) 2001-2026 Nathan Wiger and the SQL::Abstract contributors.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. See LICENSE.

About

SQL::Abstract

Resources

Security policy

Stars

20 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages