Skip to content

Latest commit

 

History

History
85 lines (57 loc) · 2.47 KB

README.md

File metadata and controls

85 lines (57 loc) · 2.47 KB

SQL::Tiny, a Perl module for generating simple SQL statements

A very simple SQL-building library. It's not for all your SQL needs, only the very simple ones.

It doesn't handle JOINs. It doesn't handle subselects. It's only for simple SQL.

my ($sql,$binds) = sql_select( 'users', [ 'name', 'status' ], { status => [ 'Deleted', 'Inactive' ] }, { order_by => 'name' } );

my ($sql,$binds) = sql_insert( 'users', { name => 'Dave', status => 'Active' } );

my ($sql,$binds) = sql_update( 'users', { status => 'Inactive' }, { password => undef } );

my ($sql,$binds) = sql_delete( 'users', { status => 'Inactive' } );

In my test suites, I have a lot of ad hoc SQL queries, and it drives me nuts to have so much SQL code lying around. SQL::Tiny is for generating SQL code for simple cases.

I'd far rather have:

my ($sql,$binds) = sql_insert(
    'users',
    {
        name      => 'Dave',
        salary    => 50000,
        status    => 'Active',
        dateadded => \'SYSDATE()',
    }
);

than hand-coding:

my $sql   = 'INSERT INTO users (name,salary,status,dateadded) VALUES (:name,:status,:salary,SYSDATE())';
my $binds = {
    ':name'      => 'Dave',
    ':salary'    => 50000,
    ':status'    => 'Active',
    ':dateadded' => \'SYSDATE()',
};

or even the positional:

my $sql   = 'INSERT INTO users (name,salary,status,dateadded) VALUES (?,?,?,SYSDATE())';
my $binds = [ 'Dave', 50000, 'Active' ];

Build status of dev branch

Build Status

Installation

To install this module, run the following commands:

perl Makefile.PL
make
make test
make install

Support and Documentation

After installing, you can find documentation for this module with the perldoc command.

perldoc SQL::Tiny

You can also look for information at:

License and Copyright

Copyright (C) 2019-2020 Andy Lester

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License 2.0.