The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DBIx::NoSQL - Experimental NoSQL-ish overlay for an SQL database

VERSION

version 0.0012

SYNOPSIS

use DBIx::NoSQL;

my $store = DBIx::NoSQL->new;

$store->connect( 'store.sqlite' );

$store->set( 'Artist' => 'Smashing Pumpkins' => {
    name => 'Smashing Pumpkins',
    genre => 'rock',
    website => 'smashingpumpkins.com',
} );

$store->set( 'Artist' => 'Tool' => {
    name => 'Tool',
    genre => 'rock',
} );

$store->search( 'Artist' )->count; # 2

my $artist = $store->get( 'Artist' => 'Smashing Pumpkins' );

# Set up a (searchable) index on the name field
$store->model( 'Artist' )->field( 'name' => ( index => 1 ) );
$store->model( 'Artist' )->reindex;

for $artist ( $store->search( 'Artist' )->order_by( 'name DESC' )->all ) {
    ...
}

$store->model( 'Album' )->field( 'released' => ( index => 1, isa => 'DateTime' ) );

$store->set( 'Album' => 'Siamese Dream' => {
    artist => 'Smashing Pumpkins',
    released => DateTime->new( ... ),
} );

my $album = $store->get( 'Album' => 'Siamese Dream' );
my $released = $album->{ released }; # The field is automatically inflated
print $release->strftime( ... );

DESCRIPTION

DBIx::NoSQL is a layer over DBI that presents a NoSQLish way to store and retrieve data. You do not need to prepare a schema beforehand to start putting data in!

Currently, data setting/getting works by using JSON for serialization and SQLite as the database (though additional database support should not be difficult to implement)

The API is fairly sane, though still an early "alpha." At the moment, a better name for this package might be "DBIx::NoSQLite"

USAGE

$store = DBIx::NoSQL->new

Returns a new DBIx::NoSQL store

$store->connect( $path )

Connect to (creating if necessary) the SQLite database located at $path

$store->set( $model, $key, $value )

Set $key (a string) to $value (a HASH reference) in $model

If $model has index, this command will also update the index entry corresponding to $key

$value = $store->get( $model, $key )

Get $value matching $key in $model

$value = $store->delete( $model, $key )

Delete the entry matching $key in $model

If $model has index, this command will also delete the index entry corresponding to $key

Search USAGE

$search = $store->search( $model, [ $where ] )

$search = $store->search( 'Artist' => { name => { -like => 'Smashing%' } } )

Return a DBIx::NoSQL::Search object for $model, filtering on the optional $where

An index is required for the filtering columns

Refer to SQL::Abstract for the format of $where (actually uses DBIx::Class::SQLMaker under the hood)

@all = $search->all

Returns every result for $search in a list

Returns an empty list if nothing is found

$result = $search->next

Returns the next item found for $search via $search->cursor

Returns undef if nothing is left for $search

$sth = $search->cursor->sth

Returns the DBI sth (statement handle) for $search

$search = $search->search( $where )

Further refine the search in the same way $search->where( ... ) does

$search = $search->where( $where )

$search = $search->where( { genre => 'rock' } ) 

Further refine $search with the given $where

A new object is cloned from the original, which is left untouched

An index is required for the filtering columns

Refer to SQL::Abstract for the format of $where (actually uses DBIx::Class::SQLMaker under the hood)

$search = $search->order_by( $order_by )

Return the results in the given order

A new object is cloned from the original, which is left untouched

An index is required for the ordering columns

Refer to SQL::Abstract for the format of $order_by (actually uses DBIx::Class::SQLMaker under the hood)

...

For additional usage, see SYNOPSIS or look at the code

More documentation forthcoming

SEE ALSO

KiokuDB

DBIx::Class

AUTHOR

Robert Krimen <robertkrimen@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Robert Krimen.

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