<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    DBIx::ThinSQL - A lightweight SQL helper for DBI

VERSION
    0.0.32 (2014-10-30) development release.

SYNOPSIS
        use strict;
        use warnings;
        use DBIx::ThinSQL qw/ bv qv /;

        my $db = DBIx::ThinSQL-&gt;connect(
            'dbi:Driver:...'
            'username',
            'password',
        );

        # Some basic CrUD statements to show the simple stuff first. Note
        # the inline binding of data that you normally have to call
        # $dbh-&gt;bind_param() on.

        my $success = $db-&gt;xdo(
            insert_into =&gt; 'actors',
            values      =&gt; {
                id    =&gt; 1,
                name  =&gt; 'John Smith',
                photo =&gt; bv( $image, DBI::SQL_BLOB ),
            },
        );

        # A "where" with a HASHref "AND"s the elements together

        my $count = $db-&gt;xdo(
            update =&gt; 'actors',
            set    =&gt; { name =&gt; 'Jack Smith' },
            where  =&gt; { id =&gt; 1, name =&gt; \'IS NOT NULL' },
        );

        # A "where" with an ARRAYref concatenates items together. Note the
        # string that is quoted according to the database type.

        my $count = $db-&gt;xdo(
            delete_from =&gt; 'actors',
            where       =&gt; [
                '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-&gt;xhashref(
            select =&gt; [ 'id', 'name', qv("Some string") ],
            from   =&gt; 'actors',
            where  =&gt; [
                'id = ', qv( 1, DBI::SQL_INTEGER ),
                ' AND photo IS NOT NULL',
            ],
            limit  =&gt; 1,
        );

        $db-&gt;xdo(
            insert_into =&gt; [ 'table', 'col1', 'col2', 'col3' ],
            select =&gt; [ 't1.col3', 't3.col4', bv( 'value', DBI::SQL_VARCHAR ) ],
            from   =&gt; 'table AS t1',
            inner_join =&gt; 'other_table AS t2',
            on         =&gt; 't1.something = t2.else',
            left_join  =&gt; 'third_table AS t3',
            on    =&gt; [ 't3.dont = t1.care AND t1.fob = ', qv( 1, DBI::SQL_INT ) ],
            where =&gt; [],
            order_by =&gt; [ 't3.dont', 't1.col4' ],
            limit    =&gt; 2,
        );

        $db-&gt;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
    xprepare
        Does a prepare 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( &amp;coderef )
        Runs the &amp;coderef subroutine inside an SQL transaction. If &amp;coderef
        raises an exception then the transaction is rolled back and the
        error gets re-thrown.

        Calls to "txn" can be nested. Savepoints will be used by nested
        "txn" calls for databases that support them.

    dump( $sql, [ @bind_values ] )
    xdump( @tokens )
        Debugging shortcut methods. Take either an SQL string (for "dump")
        or a set of tokens (for "xdump"), run the query, and then call the
        "dump_results" (which pretty-prints to STDOUT) on the resulting
        statement handle.

    log_debug( $sql, [ @bind_values ] )
        Like "dump" but sends the results to Log::Any "debug()".

STH METHODS
    val -&gt; SCALAR
        Return the first value of the first row as a scalar.

    list -&gt; LIST
        Return the first row from the query as a list.

    arrayref -&gt; ARRAYREF
        Return the first row from the query as an array reference.

    arrayrefs -&gt; ARRAYREF
    arrayrefs -&gt; LIST
        Update rows in the database and return the number of rows affected.
        This method is retricted to the wholesale replacement of column
        values (no database-side calculations etc). Multiple WHERE
        key/values are only 'AND'd together. An 'undef' value maps to SQL's
        NULL value.

    hashref -&gt; HASHREF
        Delete rows from the database and return the number of rows
        affected.

    hashrefs -&gt; ARRAYREF[HASHREF]
    hashrefs -&gt; LIST
        Delete rows from the database and return the number of rows
        affected.

CLASS FUNCTIONS
    The following functions can be exported individually or all at once
    using the ':all' tag. They all return an object which can be combined
    with or used inside other functions.

    bv( $value, [ $bind_type ] ) -&gt; DBIx::ThinSQL::BindValue
        This function returns an object which tells DBIx::ThinSQL to bind
        $value using a placeholder. The optional $bind_type is a database
        type (integer, varchar, timestamp, bytea, etc) which will be
        converted to the appropriate bind constant during a prepare() or
        prepare_cached() call.

    qv( $value )
    AND
    OR
    "sq ( @subquery )" -&gt; DBIx::ThinSQL::_expr
        A function for including a sub query inside another:

            $db-&gt;xarrayref(
                select =&gt; 'subquery.col',
                from   =&gt; sq(
                    select =&gt; 'col',
                    from   =&gt; 'table',
                    where  =&gt; 'condition IS NOT NULL',
                )-&gt;as('subquery'),
            );

    sql_and( @args ) -&gt; DBIx::ThinSQL::Expr
        Maps to "$arg1 AND $arg2 AND ...".

    sql_case( @stmts ) -&gt; DBIx::ThinSQL::Expr
        Wraps @stmts inside a CASE/END pair while converting arguments to
        expressions where needed.

            sql_case(
                when =&gt; $actors-&gt;name-&gt;is_null,
                then =&gt; 'No Name',
                else =&gt; $actors-&gt;name,
            )-&gt;as('name')

            # CASE WHEN actors0.name IS NULL
            # THEN ? ELSE actors0.name END AS name

    sql_coalesce(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "COALESCE($arg1, $arg2, ...)".

    sql_cast($arg1, as =&gt; $arg2) -&gt; DBIx::ThinSQL::Expr
        Maps to "CAST( $arg1 AS $arg2 )".

    sql_concat(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "$arg1 || $arg2 || ...".

    sql_count(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "COUNT($arg1, $arg2, ...)".

    sql_exists(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "EXISTS(@args)".

    sql_func('myfunc', @args) -&gt; DBIx::ThinSQL::Expr
        Maps to "MYFUNC($arg1, $arg2, ...)".

    sql_hex(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "HEX($arg1, $arg2, ...)".

    sql_length(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "LENGTH(@args)".

    sql_lower(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "LOWER(@args)".

    sql_ltrim(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "LTRIM(@args)".

    sql_max(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "MAX(@args)".

    sql_min(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "MIN(@args)".

    sql_rtrim(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "RTRIM(@args)".

    sql_sum(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "MIN(@args)".

    sql_or(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "$arg1 OR $arg2 OR ...".

    sql_replace(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "REPLACE($arg1,$arg2 [,$arg3])".

    sql_substr(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "SUBSTR($arg1, $arg2, ...)".

    sql_table($name, @columns) -&gt; DBIx::ThinSQL::Expr
        Maps to "name(col1,col2,...)".

    sql_upper(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "UPPER(@args)".

    sql_values(@args) -&gt; DBIx::ThinSQL::Expr
        Maps to "VALUES($arg1, $arg2, ...)".

SEE ALSO
    Log::Any

DEVELOPMENT &amp; SUPPORT
    DBIx::ThinSQL is managed via Github:

        https://github.com/mlawren/p5-DBIx-ThinSQL/tree/devel

    DBIx::ThinSQL follows a semantic versioning scheme:

        http://semver.org

AUTHOR
    Mark Lawrence &lt;nomad@null.net&gt;

COPYRIGHT AND LICENSE
    Copyright (C) 2013 Mark Lawrence &lt;nomad@null.net&gt;

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 3 of the License, or (at your
    option) any later version.

</pre></body></html>