NAME

DBIx::SQLite::Simple::Table - superclass only used to handle SQL tables

SYNOPSIS

# Example of a table with a primary key

package TPub;

require DBIx::SQLite::Simple::Table;
require Class::Gomor::Hash;
our @ISA = qw(DBIx::SQLite::Simple::Table Class::Gomor::Hash);

our @AS = qw(
   idPub
   pub
);
__PACKAGE__->buildAccessorsScalar(\@AS);

# 'our $Id' and 'our @Fields' are named Id and Fields for a good
# reason, so do not name these variables by another name.
our $Id     = $AS[0];
our @Fields = @AS[1..$#AS];

1;

# Example of a table with no key at all

package TBeer;

require DBIx::SQLite::Simple::Table;
require Class::Gomor::Hash;
our @ISA = qw(DBIx::SQLite::Simple::Table Class::Gomor::Hash);

our @AS = qw(
   beer
   country
);
__PACKAGE__->buildAccessorsScalar(\@AS);

our @Fields = @AS;

1;

# Now, we have two tables, we can play with the database

package main;

require DBIx::SQLite::Simple;
my $db = DBIx::SQLite::Simple->new(db => 'sqlite.db');

# Create to object to play with the two tables
my $tPub = TPub->new;
my $tBeer = TBeer->new;

# Create tables
$tPub->create unless $tPub->exists;
$tBeer->create unless $tBeer->exists;

# Create some entries
my @pubEntries;
push @pubEntries, TPub->new(pub => $_) for (qw(corner friends));

my @beerEntries;
push @beerEntries, TBeer->new(beer => $_, country => 'BE')
   for (qw(grim leffe bud));

# Now insert those entries;
$tPub->insert(\@pubEntries);
$tBeer->insert(\@beerEntries);

# Get friends pub
my $friends = $tPub->select(pub => 'friends');

# Lookup id
my $id = $tPub->lookupId(pub => 'friends');

# Lookup string
my $str = $tPub->lookupString('pub', idPub => $id);

# Add a beer from 'chez moi'
my $dremmwel = TBeer->new(beer => 'Dremmwel', country => '?');
$tBeer->insert([ $dremmwel ]);

$tPub->commit;
$tBeer->commit;

# Update Dremmwel
my $dremmwelOld = $dremmwel->clone;
$dremmwel->country('BZH');
$tBeer->update([ $dremmwel ], $dremmwelOld);
$tBeer->commit;

# Delete all pubs
$tPub->delete(\@pubEntries);

ATTRIBUTES

dbo

Stores a DBIx::SQLite::Simple object.

METHODS

new

Object creator. Will return an object used to access corresponding SQL table. You can pass an optional parameter: dbo. By default, it uses the global variable $DBIx::SQLite::Simple::Dbo.

clone

Create a copy of the object.

commit

Just a convenient method to commit pending changes to the whole database.

create

Method to create the table.

exists

Method to verify existence of a table.

select

If called without parameters, returns the whole content as an arrayref. If called with a hash as argument containing some table fields with values, it plays as multiple where clauses (return result as an arrayref also). See SYNOPSIS.

selectById

This method returns a reference to an array with each array indice set to the corresponding table object id.

getKey

Method used to generate a unique key, using to store and retrieve a database element quickly. By default, the key is the first field in the table schema (excluding the id field). It is user responsibility to override this method to use an appropriate key.

selectByKey

Method used to cache a table content. It uses getKey to store the object into a reference to a hash. You access a cached element by calling getKey on an object.

delete($arrayref)

Deletes all entries specified in the arrayref (they are all objects of type DBIx::SQLite::Simple::Table).

insert($arrayref)

Insert all entries specified in the arrayref (they are all objects of type DBIx ::SQLite::Simple::Table).

update($arrayref)

Will update elements specified within the arrayref (they are all objects of type DBIx::SQLite::Simple::Table). If an additionnal argument is passed, it will act as a where clause. See SYNOPSIS.

lookupId(%hash)

Returns the the id if the specified field/value hash.

lookupString($field, field2 => value)

Returns the content of the specified field. See SYNOPSIS.

AUTHOR

Patrice <GomoR> Auffret

COPYRIGHT AND LICENSE

Copyright (c) 2005-2006, Patrice <GomoR> Auffret

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.