DBIx-QuickORM

 view release on metacpan or  search on metacpan

lib/DBIx/QuickORM.pm  view on Meta::CPAN

transaction usable. On DuckDB, which has no savepoints, the open transaction
is used as it is.

The returned rows come in the order the database gives them, with the table's
default fields.

Without C<RETURNING> (MySQL) each row holds only its primary key, so every
row must carry its whole primary key. A row without it, or a table without a
primary key, croaks before anything is sent. Use C<count> or void context.

=back

=cut

sub insert_many { my $self = shift; $self->_primitive(insert_many => [], @_) }

=pod

=over 4

=item $row = $orm->update_row($table, $row_or_data, \%changes, %opts)

=item \%data = $orm->update_row($table, $row_or_data, \%changes, data => 1, %opts)

Updates the row with the row data's primary key and returns it, or undef when
no row matched. At least one change is required. A row object given follows
the rule in L</"CRUD operations">.

Options:

=over 4

=item enforce_canon => $bool

When true, croaks unless the row data is canonical (see C<is_canon>). Undef or
absent means true inside a transaction, otherwise the ORM's C<enforce_canon>.

0 skips that check, but C<cas> and C<auto_cas> still apply. It also skips the
row state checks: a row not in the database (vivified, or deleted) is still
updated by its key, where the row's own C<update> croaks. Not recommended.

=item cas => \@fields

Compare-and-swap: update only while these fields still hold the row data's
values (undef matches NULL). Otherwise return undef and change nothing. Each
field must be in the row data, or it croaks.

It compares with C<=>, so it does not suit floats, PostgreSQL C<json>, or
MySQL C<JSON>.

=item auto_cas => $bool

Compare-and-swap on every field present in both the row data and the changes.

=back

=back

=cut

sub update_row { my $self = shift; $self->_primitive(update_row => [], @_) }

=pod

=over 4

=item $count = $orm->delete_row($table, $row_or_data, enforce_canon => $bool, raw => $bool)

Deletes the row with the row data's primary key and returns how many rows were
deleted (0 or 1). The ORM stops holding it and marks the row data deleted (see
C<was_deleted> in L<DBIx::QuickORM::Role::Row>).

A delete that matches no row also marks it deleted (it is not in the
database) and returns 0.

C<enforce_canon> is as for C<update_row>, including what 0 bypasses.

=back

=cut

sub delete_row {
    my $self = shift;
    return $self->connection->delete_row(@_);
}

=pod

=over 4

=item $row = $orm->refresh_row($table, $row_or_data, cache => $bool, db => $bool, fields => \@fields, raw => $bool)

=item \%data = $orm->refresh_row($table, $row_or_data, data => 1, %opts)

The canonical row for a primary key, or undef when there is none. It takes row
data, a row, or a primary key in any form (a value, an arrayref, or a
hashref).

A row object given follows the rule in L</"CRUD operations">.

It reads C<fields> plus the primary key, or the table's default fields.

By default it returns the canonical copy when that has every field asked for,
and reads the database otherwise. C<< cache => 0 >> always reads the database.
C<< db => 0 >> only looks in the cache, returning the canonical copy as it is,
or undef. Both 0 croaks.

=back

=cut

sub refresh_row { my $self = shift; $self->_primitive(refresh_row => [], @_) }

=head2 Finding by primary key

    my $user = $orm->find(users => $id);
    my $data = $orm->find(users => $id, data => 1);    # row data
    my $none = $orm->find(users => -1);                # undef

Reads one row by primary key, like C<refresh_row>. It never writes to the
database.



( run in 1.670 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )