DBIx-NinjaORM

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        - Added tests to cover DBI failures for insert(), update(), and
          remove().
        - Added 'allow_subclassing' option for retrieve_list().
        - Added new tests for pagination in retrieve_list_nocache().
        - Cleaned up tests and code.

v2.3.1  2013-01-05
        - Fixed call to selectall_arrayref() in retrieve_list_nocache() and
          added error handling (thanks Jacob Rose).
        - Added tests to cover locking with joins in retrieve_list_nocache().
        - Fixed list of locked IDs in retrieve_list_nocache().
        - retrieve_list_nocache() now ignores lock=1 for SQLite.

v2.3.0  2012-12-04
        - Refactored to use Log::Any instead of carp/confess.

v2.2.1  2012-12-04
        - Split limit and offset, for PostgreSQL.

v2.2.0  2012-12-04
        - Modified assert_dbh() to allow coderefs that return a DBI::db object

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

first. Setting C<skip_cache> to 1 forces the ORM to load the values from the
database.

	my $object = My::Model::Book->new(
		{ isbn => '9781449303587' },
		skip_cache => 1,
	) // die 'Book with ISBN 9781449303587 does not exist';

=item * lock (default: 0)

By default, the underlying row is not locked when retrieving an object via
C<new()>. Setting C<lock> to 1 forces the ORM to bypass the cache if any, and
to lock the rows in the database as it retrieves them.

	my $object = My::Model::Book->new(
		{ isbn => '9781449303587' },
		lock => 1,
	) // die 'Book with ISBN 9781449303587 does not exist';

=back

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

	{
		$fields = $quoted_table_name . '.*';
	}

	$fields .= ', ' . $args{'query_extensions'}->{'joined_fields'}
		if defined( $args{'query_extensions'}->{'joined_fields'} );

	# We need to make an exception for lock=1 when using SQLite, since
	# SQLite doesn't support FOR UPDATE.
	# Per http://sqlite.org/cvstrac/wiki?p=UnsupportedSql, the entire
	# database is locked when updating any bit of it, so we can simply
	# ignore the locking request here.
	my $lock = '';
	if ( $args{'lock'} )
	{
		my $database_type = $dbh->{'Driver'}->{'Name'} || '';
		if ( $database_type eq 'SQLite' )
		{
			$log->info(
				'SQLite does not support locking since only one process at a time is ',
				'allowed to update a given SQLite database, so lock=1 is ignored.',

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

			$lock,
		);

		my @query_values = map { @$_ } @$where_values;
		$log->debugf(
			"Performing pre-locking query:\n%s\nValues:\n%s",
			$query,
			\@query_values,
		) if $args{'show_queries'};

		my $locked_ids;
		try
		{
			local $dbh->{'RaiseError'} = 1;
			$locked_ids = $dbh->selectall_arrayref(
				$query,
				{
					Columns => [ 1 ],
				},
				@query_values
			);
		}
		catch
		{
			$log->fatalf(
				"Could not select rows in pre-locking query: %s\nQuery: %s\nValues:\n%s",
				$_,
				$query,
				\@query_values,
			);
			croak "Failed select: $_";
		};

		if ( !defined( $locked_ids ) || ( scalar( @$locked_ids ) == 0 ) )
		{
			return [];
		}

		$where = sprintf(
			'WHERE %s.%s IN ( %s )',
			$quoted_table_name,
			$quoted_primary_key_name,
			join( ', ', ( ('?') x scalar( @$locked_ids ) ) ),
		);
		$where_values = [ [ map { $_->[0] } @$locked_ids ] ];
		$lock = '';
	}

	# Prepare the query elements.
	my $query = sprintf(
		q|
			SELECT %s
			FROM %s
			%s %s %s %s %s
		|,



( run in 1.214 second using v1.01-cache-2.11-cpan-49f99fa48dc )