NAME

Yote::SQLObjectStore::StoreBase - Base class for SQL-backed object stores

SYNOPSIS

use Yote::SQLObjectStore;

my $store = Yote::SQLObjectStore->new( 'SQLite',
    BASE_DIRECTORY => '/path/to/data',
    root_package   => 'MyApp::Root',
);

# Generate tables for your object classes
$store->make_all_tables(@INC);

$store->open;

my $root = $store->fetch_root;

my $user = $store->new_obj( 'MyApp::User', name => 'Alice' );
$root->get_users->{alice} = $user;

$store->save;

DESCRIPTION

StoreBase provides the core functionality for SQL-backed object stores, supporting both SQLite and MariaDB backends.

METHODS

fetch_root()

Returns the root node of the object store.

save (obj)

If given an object, saves that object.

If not given an object, saves all objects marked dirty.

fetch( $id )

Returns the object with the given id.

is_dirty(obj)

Returns true if the object is a base storable object that needs saving.

_validate_finder_field( $class, $field )

Validates that a field exists in the class and is a scalar (searchable) column. Dies with descriptive error if validation fails.

find_by( $class, $field, $value )

Finds a single object of the given class where field equals value. Returns the object or undef if not found.

my $user = $store->find_by('MyApp::User', 'email', 'bob@example.com');

find_all_by( $class, $field, $value, %options )

Finds all objects of the given class where field equals value. Returns a list of objects (possibly empty).

Options: limit => N - Limit results to N objects offset => N - Skip first N results order_by => 'field ASC' - Sort results (field name validated)

my @users = $store->find_all_by('MyApp::User', 'status', 'active',
    order_by => 'name ASC',
    limit => 10
);

find_where( $class, %criteria )

Finds objects matching all criteria (AND logic). Returns a list of objects, or a single object if _single => 1.

Special keys in criteria: _limit => N - Limit results _offset => N - Skip first N results _order_by => 'field ASC' - Sort results _single => 1 - Return single object or undef

my @admins = $store->find_where('MyApp::User',
    status => 'active',
    role   => 'admin',
    _order_by => 'name ASC'
);

my $user = $store->find_where('MyApp::User',
    email => 'bob@example.com',
    _single => 1
);