Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nothingmuch/kiokudb-backend-dbi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: doy/kiokudb-backend-dbi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Dec 6, 2010

  1. Copy the full SHA
    4209b0b View commit details
  2. Copy the full SHA
    1c36937 View commit details
  3. use "values" to store the subqueries

    this makes it compatible with the current query class.
    ruoso committed Dec 6, 2010
    Copy the full SHA
    c47531c View commit details
  4. Copy the full SHA
    3b68db6 View commit details

Commits on Dec 10, 2010

  1. preparing release

    ruoso committed Dec 10, 2010
    Copy the full SHA
    f5c7aa8 View commit details
  2. Copy the full SHA
    8807f05 View commit details

Commits on Dec 18, 2010

  1. small fix in release

    ruoso committed Dec 18, 2010
    Copy the full SHA
    1f2e355 View commit details
  2. Revert "small fix in release"

    This reverts commit 1f2e355.
    ruoso committed Dec 18, 2010
    Copy the full SHA
    894fc32 View commit details
  3. small fix in release

    ruoso committed Dec 18, 2010
    Copy the full SHA
    40e7c8b View commit details
  4. annotate 1.17

    ruoso committed Dec 18, 2010
    Copy the full SHA
    48567d4 View commit details

Commits on Jan 4, 2011

  1. fix building of set subqueries

    parenthesis are not always accepted.
    Also, includes an actual test
    ruoso committed Jan 4, 2011
    Copy the full SHA
    5d2d3b9 View commit details

Commits on May 4, 2011

  1. Copy the full SHA
    44d6a7d View commit details
  2. don't use source_bind_attributes

    arcanez authored and doy committed May 4, 2011
    Copy the full SHA
    6fdb344 View commit details
  3. Copy the full SHA
    39fdfa7 View commit details
  4. Copy the full SHA
    c2633c7 View commit details
  5. more dzil fiddling

    doy committed May 4, 2011
    Copy the full SHA
    b370510 View commit details
  6. Copy the full SHA
    044795f View commit details
  7. Copy the full SHA
    4f96f74 View commit details
  8. changelog and version bump

    doy committed May 4, 2011
    Copy the full SHA
    4a1b1a9 View commit details
  9. don't care about pod coverage

    doy committed May 4, 2011
    Copy the full SHA
    6e93046 View commit details

Commits on Jul 13, 2011

  1. make undocumented gin_index arg work correctly

    Arthur Axel 'fREW' Schmidt committed Jul 13, 2011
    Copy the full SHA
    0dac5de View commit details

Commits on Oct 4, 2011

  1. changelog and version bump

    doy committed Oct 4, 2011
    Copy the full SHA
    ed2dc2a View commit details

Commits on Jul 6, 2012

  1. Copy the full SHA
    8764034 View commit details
  2. typo fix (Tim Retout)

    doy committed Jul 6, 2012
    Copy the full SHA
    d303dfa View commit details
  3. Copy the full SHA
    7707c03 View commit details
  4. version bump

    doy committed Jul 6, 2012
    Copy the full SHA
    aa7d854 View commit details

Commits on Mar 30, 2014

  1. Copy the full SHA
    d6910c7 View commit details

Commits on Mar 31, 2014

  1. Merge pull request #3 from pecastro/master

    Class::MOP::load_class has been deprecated. Use Class::Load.
    doy committed Mar 31, 2014
    Copy the full SHA
    cc3dc6c View commit details
25 changes: 25 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
1.22
- Fix lookup of invalid entries that differ from a valid entry only in case

1.21
- Fix undocumented gin_index option to define_kiokudb_schema (frew)

1.20
- Fix some stuff with recent DBIx::Class (arcanez)

1.19
- Merge releases

1.16 (NUFFIN)
- Updated to support change in DBIC object hierarchy

1.18
- Fix set subquery building. Bad use of parenthesis.
- Includes an actual test for the set query.

1.17
- Small fix in release process

1.16 (DRUOSO)
- Adds support for Set GIN queries

1.15
- Constructing a KiokuDB directory handle is no longer mandatory, you can
get it from the DBIC schema (domm, nothingmuch)
16 changes: 9 additions & 7 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
name = KiokuDB-Backend-DBI
version = 1.15
version = 1.22
author = Yuval Kogman
license = Perl_5
copyright_holder = Yuval Kogman, Infinity Interactive

; authordep Dist::Zilla::PluginBundle::NUFFIN
[@Filter]
-bundle = @NUFFIN
-remove = MakeMaker
-remove = EOLTests ; fails for MakeMaker::Awesome
-remove = Signature
-remove = PodWeaver ; don't break shit yet, next release

dist = KiokuDB-Backend-DBI
repository_at = github

; authordep Dist::Zilla::Plugin::MakeMaker::Awesome
[=inc::DBICOptionalDeps]

[Prereq / ConfigureRequires]
[Prereqs / ConfigureRequires]
DBIx::Class::Optional::Dependencies = 0

[InjectMeta]
[=inc::DistMeta]
dynamic_config = 1

[Prereq]
[Prereqs]
Moose = 0
MooseX::Types = 0.08
MooseX::Types::Moose = 0

KiokuDB = 0.46
DBIx::Class = 0.08123
DBIx::Class = 0.08127
DBI = 1.607

Data::Stream::Bulk = 0.07
@@ -37,4 +39,4 @@ Test::More = 0.88
Test::TempDir = 0

SQL::Abstract = 0
Search::GIN = 0
Search::GIN = 0.07
31 changes: 31 additions & 0 deletions inc/DistMeta.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package inc::DistMeta;
use Moose;

has metadata => (
is => 'ro',
isa => 'HashRef',
required => 1,
);

with 'Dist::Zilla::Role::MetaProvider';

around BUILDARGS => sub {
my $orig = shift;
my $self = shift;

my $params = $self->$orig(@_);

my $zilla = delete $params->{zilla};
my $plugin_name = delete $params->{plugin_name};

return {
zilla => $zilla,
plugin_name => $plugin_name,
metadata => $params,
};
};

__PACKAGE__->meta->make_immutable;
no Moose;

1;
9 changes: 9 additions & 0 deletions lib/DBIx/Class/KiokuDB/EntryProxy.pm
Original file line number Diff line number Diff line change
@@ -44,3 +44,12 @@ DBIx::Class::KiokuDB::EntryProxy - A proxying result class for KiokuDB objects
This class implements the necessary glue to properly inflate resultsets for
L<KiokuDB> object into proper instances using L<KiokuDB>.
=begin Pod::Coverage
new
inflate_result
=end Pod::Coverage
=cut
22 changes: 18 additions & 4 deletions lib/DBIx/Class/Schema/KiokuDB.pm
Original file line number Diff line number Diff line change
@@ -81,12 +81,15 @@ sub define_kiokudb_schema {
my $gin_index_source_name = $args{gin_index_source} ||= $args{gin_index_table};

my $entries = $self->define_kiokudb_entries_resultsource(%args);
my $gin_index = $self->define_kiokudb_gin_index_resultsource(%args) if $args{gin_index};

my $schema = $args{schema};

$schema->register_source( $entries_source_name => $entries );
$schema->register_source( $gin_index_source_name => $gin_index );
if ($args{gin_index}) {
my $gin_index = $self->define_kiokudb_gin_index_resultsource(%args);
$schema->register_source( $gin_index_source_name => $gin_index );
}


$schema->kiokudb_entries_source_name($entries_source_name)
unless $schema->kiokudb_entries_source_name;
@@ -133,7 +136,7 @@ sub define_kiokudb_gin_index_resultsource {
value => { data_type => "varchar" },
);

$gin_index->add_relationship('entry_ids', $args{entries_source}, { 'foreign.id' => 'me.id' });
$gin_index->add_relationship('entry_ids', $args{entries_source}, { 'foreign.id' => 'self.id' });

$gin_index->sqlt_deploy_callback(sub {
my ($source, $sqlt_table) = @_;
@@ -231,7 +234,7 @@ L<KiokuDB> and than link that to some L<DBIx::Class> classes. Another
use case is that you already have a configured L<DBIx::Class> Schema
and want to tack L<KiokuDB> onto it.
The trick here is to make sure to load the L<KiokuDB> schema using
The trick here is to make sure to load the L<KiokuDB> schema using
C<< __PACKAGE__->define_kiokudb_schema() >> in your Schema class:
package MyApp::DB;
@@ -268,3 +271,14 @@ L<DBIx::Class>.
=head1 SEE ALSO
L<DBIx::Class::KiokuDB>, L<KiokuDB::Backend::DBI>.
=begin Pod::Coverage
define_kiokudb_entries_resultsource
define_kiokudb_gin_index_resultsource
define_kiokudb_schema
kiokudb_handle
=end Pod::Coverage
=cut
120 changes: 92 additions & 28 deletions lib/KiokuDB/Backend/DBI.pm
Original file line number Diff line number Diff line change
@@ -16,11 +16,13 @@ use Data::Stream::Bulk::DBI;
use SQL::Abstract;
use JSON;
use Scalar::Util qw(weaken refaddr);
use List::MoreUtils qw(any);
use Class::Load qw(load_class);

use KiokuDB::Backend::DBI::Schema;
use KiokuDB::TypeMap;
use KiokuDB::TypeMap::Entry::DBIC::Row;
use KiokuDB::TypeMap::Entry::DBIC::ResultSourceHandle;
use KiokuDB::TypeMap::Entry::DBIC::ResultSource;
use KiokuDB::TypeMap::Entry::DBIC::ResultSet;
use KiokuDB::TypeMap::Entry::DBIC::Schema;

@@ -47,7 +49,7 @@ my %reserved_cols = ( map { $_ => 1 } @reserved_cols );

subtype ValidColumnName, as Str, where { not exists $reserved_cols{$_} };
subtype SchemaProto, as Defined, where {
Class::MOP::load_class($_) unless ref;
load_class($_) unless ref;
!ref($_) || blessed($_) and $_->isa("DBIx::Class::Schema::KiokuDB");
};

@@ -329,14 +331,14 @@ sub default_typemap {
KiokuDB::TypeMap->new(
isa_entries => {
# redirect to schema row
'DBIx::Class::Row' => KiokuDB::TypeMap::Entry::DBIC::Row->new,
'DBIx::Class::Row' => KiokuDB::TypeMap::Entry::DBIC::Row->new,

# actual serialization
'DBIx::Class::ResultSet' => KiokuDB::TypeMap::Entry::DBIC::ResultSet->new,
'DBIx::Class::ResultSet' => KiokuDB::TypeMap::Entry::DBIC::ResultSet->new,

# fake, the entries never get written to the db
'DBIx::Class::ResultSourceHandle' => KiokuDB::TypeMap::Entry::DBIC::ResultSourceHandle->new,
'DBIx::Class::Schema' => KiokuDB::TypeMap::Entry::DBIC::Schema->new,
'DBIx::Class::ResultSource' => KiokuDB::TypeMap::Entry::DBIC::ResultSource->new,
'DBIx::Class::Schema' => KiokuDB::TypeMap::Entry::DBIC::Schema->new,
},
);
}
@@ -454,7 +456,7 @@ sub insert_rows {
}
}

my $bind_attributes = $self->storage->source_bind_attributes($self->schema->source("entries"));
my $colinfo = $self->schema->source('entries')->columns_info;

my %rows = ( insert => $insert, update => $update );

@@ -467,9 +469,9 @@ sub insert_rows {
foreach my $column_name (@cols) {
my $attributes = {};

if( $bind_attributes ) {
$attributes = $bind_attributes->{$column_name}
if defined $bind_attributes->{$column_name};
if ( exists $colinfo->{$column_name} ) {
my $dt = $colinfo->{$column_name}{data_type};
$attributes = $self->storage->bind_attribute_by_data_type($dt);
}

$sth->bind_param_array( $i, $rows{$op}->{$column_name}, $attributes );
@@ -684,11 +686,14 @@ sub get {
? ( data => $self->schema,
class => "DBIx::Class::Schema" )
: ( data => undef,
class => "DBIx::Class::ResultSourceHandle" )
class => "DBIx::Class::ResultSource" )
);
}

return if @rows_and_ids != keys %entries; # ->rows only works after we're done
# ->rows only works after we're done
return if @rows_and_ids != keys %entries;
# case sensitivity differences, possibly?
return if any { !defined } @entries{@rows_and_ids};

map { ref($_) ? $_ : $self->deserialize($_) } @entries{@rows_and_ids};
}
@@ -881,24 +886,43 @@ sub search {
);

my %spec = $query->extract_values($self);
my @binds;

my @v = @{ $spec{values} };
my $inner_sql = $self->_search_gin_subquery(\%spec, \@binds);
return $self->_select_entry_stream("SELECT data FROM entries WHERE id IN (".$inner_sql.")",@binds);
}

sub _search_gin_subquery {
my ($self, $spec, $binds) = @_;

my @v = ref $spec->{values} eq 'ARRAY' ? @{ $spec->{values} } : ();
if ( $spec->{method} eq 'set' ) {
my $op = $spec->{operation};

die 'gin set query received bad operation'
unless $op =~ /^(UNION|INTERSECT|EXCEPT)$/i;

die 'gin set query missing subqueries'
unless ref $spec->{subqueries} eq 'ARRAY' &&
scalar @{ $spec->{subqueries} };

if ( $spec{method} eq 'all' and @v > 1) {
return "(".
(
join ' '.$op.' ',
map { $self->_search_gin_subquery($_, $binds) }
@{ $spec->{subqueries} }
).")";

} elsif ( $spec->{method} eq 'all' and @v > 1) {
# for some reason count(id) = ? doesn't work
return $self->_select_entry_stream("
SELECT data FROM entries WHERE id IN (
SELECT id FROM gin_index WHERE value IN (" . join(", ", ('?') x @v) . ") GROUP BY id HAVING COUNT(id) = " . scalar(@v) . "
)",
@v
);
push @$binds, @v;
return "SELECT id FROM gin_index WHERE value IN ".
"(" . join(", ", ('?') x @v) . ")" .
"GROUP BY id HAVING COUNT(id) = " . scalar(@v);
} else {
return $self->_select_entry_stream("
SELECT data FROM entries WHERE id IN (
SELECT DISTINCT id FROM gin_index WHERE value IN (" . join(", ", ('?') x @v) . ")
)",
@v
);
push @$binds, @v;
return "SELECT DISTINCT id FROM gin_index WHERE value IN ".
"(" . join(", ", ('?') x @v) . ")";
}
}

@@ -963,6 +987,7 @@ sub drop_tables {

sub DEMOLISH {
my $self = shift;
return if $_[0];

if ( $self->has_storage ) {
$self->storage->disconnect;
@@ -978,7 +1003,7 @@ sub new_garbage_collector {
my $cmd = $args{command};
my $class = $args{class} || $cmd ? $cmd->class : "KiokuDB::GC::Naive";

Class::MOP::load_class($class);
load_class($class);

return $class->new(
%args,
@@ -1062,7 +1087,7 @@ For more details see L<DBIx::Class::Schema::KiokuDB>.
=head1 SUPPORTED DATABASES
This driver has been tested with MySQL 5 (4.1 should be the minimal supported
version), SQLite 3, and PostgresSQL 8.3.
version), SQLite 3, and PostgreSQL 8.3.
The SQL code is reasonably portable and should work with most databases. Binary
column support is required when using the L<Storable> serializer.
@@ -1290,4 +1315,43 @@ Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
rights reserved This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
=begin Pod::Coverage
BUILD
DEMOLISH
all_entries
all_entry_ids
child_entries
child_entry_ids
clear
create_tables
default_typemap
delete
entries_to_rows
entry_to_row
exists
fetch_entry
has_batch_size
insert
insert_entry
insert_rows
new_from_dsn
new_garbage_collector
prepare_insert
prepare_select
prepare_update
register_handle
remove_ids
root_entries
root_entry_ids
search
simple_search
tables_exist
txn_begin
txn_commit
txn_rollback
update_index
=end Pod::Coverage
=cut
8 changes: 8 additions & 0 deletions lib/KiokuDB/TypeMap/Entry/DBIC/ResultSet.pm
Original file line number Diff line number Diff line change
@@ -48,3 +48,11 @@ The result set is cloned, the clone will have its cache cleared, and then it is
simply serialized normally. This is the only L<DBIx::Class> related object that
is literally stored in the database, as it represents a memory resident object,
not a database resident one.
=begin Pod::Coverage
compile_collapse_body
=end Pod::Coverage
=cut
Loading