NAME

SQL::Maker - Yet another SQL builder

SYNOPSIS

use SQL::Maker;

my $builder = SQL::Maker->new(
    driver => 'SQLite', # or your favorite driver
);

# SELECT
($sql, @binds) = $builder->select($table, \@fields, \%where, \%opt);

# INSERT
($sql, @binds) = $builder->insert($table, \%values, \%opt);

# DELETE
($sql, @binds) = $builder->delete($table, \%where, \%opt);

# UPDATE
($sql, @binds) = $builder->update($table, \%set, \%where);
($sql, @binds) = $builder->update($table, \@set, \%where);

DESCRIPTION

SQL::Maker is yet another SQL builder class. It is based on DBIx::Skinny's SQL generator.

METHODS

PLUGINS

SQL::Maker features a plugin system. Write the code as follows:

package My::SQL::Maker;
use parent qw/SQL::Maker/;
__PACKAGE__->load_plugin('InsertMulti');

STRICT MODE

See http://blog.kazuhooku.com/2014/07/the-json-sql-injection-vulnerability.html for why do we need the strict mode in the first place.

In strict mode, the following parameters must be blessed references implementing as_sql and bind methods if they are NOT simple scalars (i.e. if they are references of any kind).

You can use SQL::QueryMaker objects for those parameters.

Example:

use SQL::QueryMaker qw(sql_in sql_raw);

## NG: Use array-ref for values.
$maker->select("user", ['*'], { name => ["John", "Tom"] });

## OK: Use SQL::QueryMaker
$maker->select("user", ['*'], { name => sql_in(["John", "Tom"]) });

## Also OK: $where parameter itself is a blessed object.
$maker->select("user", ['*'], $maker->new_condition->add(name => sql_in(["John", "Tom"])));
$maker->select("user", ['*'], sql_in(name => ["John", "Tom"]));


## NG: Use scalar-ref for a raw value.
$maker->insert(user => [ name => "John", created_on => \"datetime(now)" ]);

## OK: Use SQL::QueryMaker
$maker->insert(user => [name => "John", created_on => sql_raw("datetime(now)")]);

FAQ

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>

SEE ALSO

SQL::Abstract SQL::QueryMaker

The whole code was taken from DBIx::Skinny by nekokak++.

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.