NAME

Cosmic::DB - Lightweight SQL generation, portable across Oracle, MySQL, Postgres & SQL Server

SYNOPSIS

use Cosmic::DB;

DESCRIPTION

DEVELOPMENT RELEASE - Don't use this, like Magnum it's nowhere near ready.

(Yes that was a Zoolander reference)

This module acts as a gateway to Cosmic::DB::Schema and Cosmic::DB::SQL, providing some additional convenient functionality.

You may well wish to use your current DBI wrapper, such as DBIx::Simple and instantiate Cosmic::DB::Schema and Cosmic::DB::SQL directly.

USAGE

METHODS

new

Usage

my $db = new Cosmic::DB( dsn => $DSN, user => $user, pass => $pass, attrs => \%attrs);
my $dbclone = $db->new();
my $dbcopy = $db->new( param => value, attrs => \%attrs);

Purpose : Creates new Cosmic::DB instance, clones an existing instance Parameters:

    attrs => %attrs - passed to DBI connect, see L<DBI> for details
    debug = 0|1 - turn on debugging warnings
    debug_newline = "\n<br>" - for debugging newline characters
    prefix = STRING - used to prefix table names
    prefix = STRING - used to suffix table names

An instance can be cloned by calling new against it. You can optionally pass new params and attributes that will overwrite any existing ones for the clone. The clone will still need to "connect"

See Also : DBI

connect

Usage

$db->connect;
$db->connect( $dbh );

Connects with details sent to new, or can optionally be given a DBH which it's use instead. Returns true upon connection or croaks.

disconnect

Usage $db->disconnect;

Disconnects the database connection.

insert

Usage

$db->insert( $table, \@columns, \@values );
$db->insert( $table, \@columns, \%values );
$db->insert( $table, \%values );
$db->insert( $table, \@columns, [ \@values, \@values, ... ] );
$db->insert( $table, \@columns, [ \%values, \%values, ... ] );
$db->insert( $table, [ \%values, \%values, ... ] );

Purpose : Inserts \@values into the \@columns of $table Parameters:

    $table = STRING - name of the table
    \@columns = LIST - array reference to column names
    \@values = LIST - array reference to values
    \%values = HASH - hash reference to values keyed by column names

Uses do for single inserts, or prepare and a loop for multiple. If columns is ommitted and %values is a hash (or arrary ref of hashes) then the hash keys are used as the columns. If %values is a hash and columns is passed, then other hash keys are ignored.

delete

Usage

$db->delete( $table, \%where );
$db->delete( $table, \%where, \@values );

Purpose : Deletes rows from $table where %where is true for @values Parameters:

    $table = STRING - name of the table
    \%where = HASH - a L<Cosmic::DB::SQL/where> where hash
    \@values = LIST - list of values to replace placeholders

Uses do for single deletes, or prepare and a loop for multiple. Values must contain arrayref of arrayrefs if used.

update

Usage

$db->update( $table, \@columns, \@data, \%where );
$db->update( $table, \@columns, \%data, \%where );
$db->update( $table, \%data, \%where );
$db->update( $table, \@columns, [ \@data, \@data, ... ], \%where );
$db->update( $table, \@columns, [ \%data, \%data, ... ], \%where );
$db->update( $table, [ \%data, \%data, ... ], \%where );

Purpose : Updates \@data into the \@columns of $table where %where is true Parameters:

    $table = STRING - name of the table
    \@columns = LIST - array reference to column names
    \@data = LIST - array reference to values
    \%data = HASH - hash reference to values keyed by column names
    \%where = HASH - a L<Cosmic::DB::SQL/where> where hash

Uses do for single upates, or prepare and a loop for multiple. If columns is ommitted and %data is a hash (or arrary ref of hashes) then the hash keys are used as the columns. If %data is a hash and columns is passed, then other hash keys are ignored.

INTERNAL FUNCTIONS

BUGS

Use RT, or you'll probably get a better responce on the mailing list.

SUPPORT

Mailing list coming soon

AUTHOR

Lyle Hopkins
CPAN ID: cosmicnet
Bristol & Bath Perl Moungers
cosmicnet@cpan.org
http://perl.bristolbath.org

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

perl(1).