DBIx-ThinSQL

 view release on metacpan or  search on metacpan

lib/DBIx/ThinSQL.pm  view on Meta::CPAN


    # 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.
    })


=head1 DESCRIPTION

Sorry, this documentation is invalid or out of date.

B<DBIx::ThinSQL> is an extension to the Perl Database Interface
(L<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 L<DBIx::Connector>.  Security conscious coders
will be pleased to know that all user-supplied values are bound
properly using L<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 L<Log::Any> for logging.

=head1 CONSTRUCTOR

Works like a normal DBI. Can be used with things like
L<DBIx::Connector> to get nice transaction support.

=head1 DBH METHODS

=over

=item share_dir -> Path::Tiny

Returns the path to the distribution share directory. If
C<$DBIx::ThinSQL::SHARE_DIR> is set then that value will be returned
instead of the default method which uses L<File::ShareDir>.

=item throw_error

If B<DBIX::ThinSQL> or a statement raises an exception then the
C<throw_error()> method will be called. By default it just croaks but
classes that inherit from B<DBIx::ThinSQL> can override it. The
original use case was to turn database error text into blessed objects.

=item xprepare

Does a prepare but knows about bind values and quoted values.

=item xprepare_cached

Does a prepare_cached but knows about bind values and quoted values.

=item xval

Creates a statement handle using xprepare(), executes it, and returns
the result of the val() method.

=item xlist

Creates a statement handle using xprepare(), executes it, and returns
the result of the list() method.

=item xarrayref

Does a prepare but knows about bind values and quoted values.

=item xarrayrefs



( run in 1.932 second using v1.01-cache-2.11-cpan-39bf76dae61 )