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

ObjectDB - Lightweight Object-relational mapper

SYNOPSIS

DESCRIPTION

ObjectDB is a lightweight, deps free (except DBI of course) and flexible object-relational mapper.

It combines all the best features from Class::DBI, DBIx::Class and Rose::DB but stays as light as possible.

ObjectDB abstract is not that heavy as in Rose::DB: columns are not objects, everything is pretty much straight forward and flat.

Embedded SQL generator is similar to SQL::Abstract, but leaves low-level sql generation still possible.

ATTRIBUTES

is_in_db

Returns true when object was created or loaded. Otherwise false.

is_modified

Returns true when object was modified (setting columns). Otherwise false.

METHODS

new

Returns a new ObjectDB object.

init

Sets objects columns.

schema

Used to define class schema. For more information see ObjectDB::Schema.

columns

Returns object columns that are set or have a default value.

column

Gets and sets column value.

clone

Object cloning. Everything is copied except primary key and unique key values.

begin_work

Begin transaction.

rollback

Roll back transaction.

commit

Commit transaction.

create

Creates a new object. Sets auto increment field to the last inserted id.

load

Loads object using primary key or unique key that was provided when creating a new instance. Dies if there was no primary or unique key.

update

Updates object.

delete

Deletes object.

find

Find objects. The second argument is a hashref that is translated into sql. Keys that can be used:

where

Build SQL. For more information see ObjectDB::SQL.

with

Prefetch related objects.

single

By default find returns array reference, by setting single to 1 undef or one object is returned (the first one).

order_by

ORDER BY

having

HAVING

limit

LIMIT

offset

OFFSET

page

With page_size you can select specific pages without calculation limit and offset by yourself.

page_size

The size of the page. It is 20 items by default.

columns

Select only specific columns.

count

Count objects.

my $author = $article->related('author');

Gets prefetched related object(s).

Creates related objects.

Finds related objects.

Same as find_objects but sets related method.

Counts related objects.

Updates related objects. Use set key for setting new values.

Deletes related objects.

Creates and deletes related objects to satisfy the set. Usefull when setting many to many relationships.

to_hash

Serializes object to hash. All prefetched objects are serialized also.

SUPPORT

DEVELOPMENT

Repository

http://github.com/vti/object-db/commits/master

SEE ALSO

AUTHOR

Viacheslav Tykhanovskyi, vti@cpan.org.

CREDITS

In alphabetical order:

COPYRIGHT

Copyright (C) 2009, Viacheslav Tykhanovskyi.

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