DBIx-ThinSQL
view release on metacpan or search on metacpan
);
# A "where" with an ARRAYref concatenates items together. Note the
# string that is quoted according to the database type.
my $count = $db->xdo(
delete_from => 'actors',
where => [
'actor_id = 1', ' OR ',
'last_name != ', qv("Jones", DBI::SQL_VARCHAR ),
],
);
# Methods for reading from the database depend on the type of
# structure you want back: arrayref or hashref references.
my $ref = $db->xhashref(
select => [ 'id', 'name', qv("Some string") ],
from => 'actors',
where => [
'id = ', qv( 1, DBI::SQL_INTEGER ),
' AND photo IS NOT NULL',
],
limit => 1,
);
$db->xdo(
insert_into => [ 'table', 'col1', 'col2', 'col3' ],
select => [ 't1.col3', 't3.col4', bv( 'value', DBI::SQL_VARCHAR ) ],
from => 'table AS t1',
inner_join => 'other_table AS t2',
on => 't1.something = t2.else',
left_join => 'third_table AS t3',
on => [ 't3.dont = t1.care AND t1.fob = ', qv( 1, DBI::SQL_INT ) ],
where => [],
order_by => [ 't3.dont', 't1.col4' ],
limit => 2,
);
$db->txn( sub {
# Anything you like, done inside a BEGIN/COMMIT pair, with
# nested calls to txn() done inside a SAVEPOINT/RELEASE pair.
})
DESCRIPTION
Sorry, this documentation is invalid or out of date.
DBIx::ThinSQL is an extension to the Perl Database Interface (DBI).
It is designed for complicated queries and efficient access to
results. With an API that lets you easily write almost-raw SQL,
DBIx::ThinSQL gives you unfettered access to the power and
flexibility of your underlying database. It aims to be a tool for
programmers who want their databases to work just as hard as their
Perl scripts.
DBIx::ThinSQL gives you access to aggregate expressions, joins,
nested selects, unions and database-side operator invocations.
Transactional support is provided via DBIx::Connector. Security
conscious coders will be pleased to know that all user-supplied
values are bound properly using DBI "bind_param()". Binding binary
data is handled transparently across different database types.
DBIx::ThinSQL offers a couple of very simple Create, Retrieve,
Update and Delete (CRUD) action methods. These are designed to get
you up and running quickly when your query data is already inside a
hashref. The methods are abstractions of the real API, but should
still read as much as possible like SQL.
Although rows can be retrieved from the database as simple objects,
DBIx::ThinSQL does not attempt to be an Object-Relational-Mapper
(ORM). There are no auto-inflating columns or automatic joins and
the code size and speed reflect the lack of complexity.
DBIx::ThinSQL uses the light-weight Log::Any for logging.
CONSTRUCTOR
Works like a normal DBI. Can be used with things like
DBIx::Connector to get nice transaction support.
DBH METHODS
share_dir -> Path::Tiny
Returns the path to the distribution share directory. If
$DBIx::ThinSQL::SHARE_DIR is set then that value will be
returned instead of the default method which uses
File::ShareDir.
throw_error
If DBIX::ThinSQL or a statement raises an exception then the
"throw_error()" method will be called. By default it just croaks
but classes that inherit from DBIx::ThinSQL can override it. The
original use case was to turn database error text into blessed
objects.
xprepare
Does a prepare but knows about bind values and quoted values.
xprepare_cached
Does a prepare_cached but knows about bind values and quoted
values.
xval
Creates a statement handle using xprepare(), executes it, and
returns the result of the val() method.
xlist
Creates a statement handle using xprepare(), executes it, and
returns the result of the list() method.
xarrayref
Does a prepare but knows about bind values and quoted values.
xarrayrefs
Does a prepare but knows about bind values and quoted values.
xhashref
Does a prepare but knows about bind values and quoted values.
xhashrefs
Does a prepare but knows about bind values and quoted values.
txn( &coderef )
( run in 2.325 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )