my ($table, @fields, %where, %opt, %values, %set, $sql, @binds);

NAME

SQL::Maker - Yet another SQL builder

SYNOPSIS

use SQL::Maker;

my $builder = SQL::Maker->new();

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

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

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

# UPDATE
($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.

THE SOFTWARE IS IT'S IN ALPHA QUALITY. IT MAY CHANGE THE API WITHOUT NOTICE.

METHODS

my $builder = SQL::Maker->new(%args);

Create new instance of SQL::Maker.

Attributes are following:

driver: Str

Driver name is required. The driver type is needed to create SQL string.

quote_char: Str

This is the character that a table or column name will be quoted with.

Default: auto detect from $driver.

name_sep: Str

This is the character that separates a table and column name.

Default: '.'

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

This method returns SQL string and bind variables for SELECT statement.

$table

Table name in scalar.

\@fields

This is a list for retrieving fields from database.

\%where

SQL::Maker creates where clause from this hashref via SQL::Maker::Condition.

\%opt

This is a options for SELECT statement

$opt->{prefix}

This is a prefix for SELECT statement.

For example, you can provide the 'SELECT SQL_CALC_FOUND_ROWS '. It's useful for MySQL.

Default Value: 'SELECT '

$opt->{limit}

This option makes 'LIMIT $n' clause.

$opt->{offset}

This option makes 'OFFSET $n' clause.

$opt->{having}

This option makes HAVING clause

$opt->{for_update}

This option makes 'FOR UPDATE" clause.

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

Generate INSERT query.

$table

Table name in scalar.

\%values

This is a values for INSERT statement.

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

Generate DELETE query.

$table

Table name in scalar.

\%where

SQL::Maker creates where clause from this hashref via SQL::Maker::Condition.

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

Generate UPDATE query.

$table

Table name in scalar.

\%set

Setting values.

\%where

SQL::Maker creates where clause from this hashref via SQL::Maker::Condition.

PLUGINS

SQL::Maker supports plugin system. Write the code like following.

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

FAQ

Why don't you use SQL::Abstract?

I need more extensible one.

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>

SEE ALSO

SQL::Abstract

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.