Hello community, here is the log from the commit of package perl-Mojo-SQLite for openSUSE:Factory checked in at 2017-02-14 00:48:30 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Mojo-SQLite (Old) and /work/SRC/openSUSE:Factory/.perl-Mojo-SQLite.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Mojo-SQLite" Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Mojo-SQLite/perl-Mojo-SQLite.changes 2017-02-03 18:54:13.104323777 +0100 +++ /work/SRC/openSUSE:Factory/.perl-Mojo-SQLite.new/perl-Mojo-SQLite.changes 2017-02-14 00:48:31.661165285 +0100 @@ -1,0 +2,11 @@ +Sun Feb 12 06:10:45 UTC 2017 - [email protected] + +- updated to 2.000 + see /usr/share/doc/packages/perl-Mojo-SQLite/Changes + + 2.000 2017-02-11 17:03:53 EST + - Add support for generating queries with SQL::Abstract. (based on Mojo::Pg 3.0) + - Add abstract attribute to Mojo::SQLite. + - Add delete, insert, select, and update methods to Mojo::SQLite::Database. + +------------------------------------------------------------------- Old: ---- Mojo-SQLite-1.004.tar.gz New: ---- Mojo-SQLite-2.000.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Mojo-SQLite.spec ++++++ --- /var/tmp/diff_new_pack.5dlC9b/_old 2017-02-14 00:48:32.377064222 +0100 +++ /var/tmp/diff_new_pack.5dlC9b/_new 2017-02-14 00:48:32.381063658 +0100 @@ -17,7 +17,7 @@ Name: perl-Mojo-SQLite -Version: 1.004 +Version: 2.000 Release: 0 %define cpan_name Mojo-SQLite Summary: Tiny Mojolicious Wrapper for Sqlite @@ -35,6 +35,7 @@ BuildRequires: perl(Module::Build::Tiny) >= 0.034 BuildRequires: perl(Module::Metadata) BuildRequires: perl(Mojolicious) >= 7.15 +BuildRequires: perl(SQL::Abstract) >= 1.81 BuildRequires: perl(Test::More) >= 0.88 BuildRequires: perl(URI) >= 1.69 BuildRequires: perl(URI::db) >= 0.15 @@ -42,6 +43,7 @@ Requires: perl(DBD::SQLite) >= 1.50 Requires: perl(DBI) >= 1.627 Requires: perl(Mojolicious) >= 7.15 +Requires: perl(SQL::Abstract) >= 1.81 Requires: perl(URI) >= 1.69 Requires: perl(URI::db) >= 0.15 Requires: perl(URI::file) >= 4.21 ++++++ Mojo-SQLite-1.004.tar.gz -> Mojo-SQLite-2.000.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/Build.PL new/Mojo-SQLite-2.000/Build.PL --- old/Mojo-SQLite-1.004/Build.PL 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/Build.PL 2017-02-11 23:03:56.000000000 +0100 @@ -84,7 +84,7 @@ "Dan Book <dbook\@cpan.org>" ], "dist_name" => "Mojo-SQLite", - "dist_version" => "1.004", + "dist_version" => "2.000", "license" => "artistic_2", "module_name" => "Mojo::SQLite", "recursive_test_files" => 1, @@ -95,6 +95,7 @@ "File::Spec::Functions" => 0, "File::Temp" => 0, "Mojolicious" => "7.15", + "SQL::Abstract" => "1.81", "Scalar::Util" => 0, "URI" => "1.69", "URI::db" => "0.15", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/Changes new/Mojo-SQLite-2.000/Changes --- old/Mojo-SQLite-1.004/Changes 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/Changes 2017-02-11 23:03:56.000000000 +0100 @@ -1,3 +1,8 @@ +2.000 2017-02-11 17:03:53 EST + - Add support for generating queries with SQL::Abstract. (based on Mojo::Pg 3.0) + - Add abstract attribute to Mojo::SQLite. + - Add delete, insert, select, and update methods to Mojo::SQLite::Database. + 1.004 2017-01-17 00:10:51 EST - Use Mojo::File from Mojolicious 7.15 instead of deprecated Mojo::Util slurp function. (#9) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/MANIFEST new/Mojo-SQLite-2.000/MANIFEST --- old/Mojo-SQLite-1.004/MANIFEST 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/MANIFEST 2017-02-11 23:03:56.000000000 +0100 @@ -31,6 +31,7 @@ t/00-report-prereqs.dd t/00-report-prereqs.t t/connection.t +t/crud.t t/database.t t/migrations.t t/migrations/test.sql diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/META.json new/Mojo-SQLite-2.000/META.json --- old/Mojo-SQLite-1.004/META.json 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/META.json 2017-02-11 23:03:56.000000000 +0100 @@ -44,6 +44,7 @@ "File::Spec::Functions" : "0", "File::Temp" : "0", "Mojolicious" : "7.15", + "SQL::Abstract" : "1.81", "Scalar::Util" : "0", "URI" : "1.69", "URI::db" : "0.15", @@ -65,28 +66,28 @@ "provides" : { "Mojo::SQLite" : { "file" : "lib/Mojo/SQLite.pm", - "version" : "1.004" + "version" : "2.000" }, "Mojo::SQLite::Database" : { "file" : "lib/Mojo/SQLite/Database.pm", - "version" : "1.004" + "version" : "2.000" }, "Mojo::SQLite::Migrations" : { "file" : "lib/Mojo/SQLite/Migrations.pm", - "version" : "1.004" + "version" : "2.000" }, "Mojo::SQLite::PubSub" : { "file" : "lib/Mojo/SQLite/PubSub.pm", - "version" : "1.004", + "version" : "2.000", "x_deprecated" : 1 }, "Mojo::SQLite::Results" : { "file" : "lib/Mojo/SQLite/Results.pm", - "version" : "1.004" + "version" : "2.000" }, "Mojo::SQLite::Transaction" : { "file" : "lib/Mojo/SQLite/Transaction.pm", - "version" : "1.004" + "version" : "2.000" } }, "release_status" : "stable", @@ -102,7 +103,7 @@ }, "x_IRC" : "irc://irc.perl.org/#mojo" }, - "version" : "1.004", + "version" : "2.000", "x_Dist_Zilla" : { "perl" : { "version" : "5.024000" @@ -296,7 +297,7 @@ "branch" : null, "changelog" : "Changes", "signed" : 0, - "tag" : "v1.004", + "tag" : "v2.000", "tag_format" : "v%v", "tag_message" : "v%v" }, @@ -630,6 +631,6 @@ "Dan Book <[email protected]>", "Dan Book <[email protected]>" ], - "x_serialization_backend" : "Cpanel::JSON::XS version 3.0225" + "x_serialization_backend" : "Cpanel::JSON::XS version 3.0226" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/META.yml new/Mojo-SQLite-2.000/META.yml --- old/Mojo-SQLite-1.004/META.yml 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/META.yml 2017-02-11 23:03:56.000000000 +0100 @@ -26,23 +26,23 @@ provides: Mojo::SQLite: file: lib/Mojo/SQLite.pm - version: '1.004' + version: '2.000' Mojo::SQLite::Database: file: lib/Mojo/SQLite/Database.pm - version: '1.004' + version: '2.000' Mojo::SQLite::Migrations: file: lib/Mojo/SQLite/Migrations.pm - version: '1.004' + version: '2.000' Mojo::SQLite::PubSub: file: lib/Mojo/SQLite/PubSub.pm - version: '1.004' + version: '2.000' x_deprecated: 1 Mojo::SQLite::Results: file: lib/Mojo/SQLite/Results.pm - version: '1.004' + version: '2.000' Mojo::SQLite::Transaction: file: lib/Mojo/SQLite/Transaction.pm - version: '1.004' + version: '2.000' requires: Carp: '0' DBD::SQLite: '1.50' @@ -50,6 +50,7 @@ File::Spec::Functions: '0' File::Temp: '0' Mojolicious: '7.15' + SQL::Abstract: '1.81' Scalar::Util: '0' URI: '1.69' URI::db: '0.15' @@ -60,7 +61,7 @@ bugtracker: https://github.com/Grinnz/Mojo-SQLite/issues homepage: https://github.com/Grinnz/Mojo-SQLite repository: https://github.com/Grinnz/Mojo-SQLite.git -version: '1.004' +version: '2.000' x_Dist_Zilla: perl: version: '5.024000' @@ -210,7 +211,7 @@ branch: ~ changelog: Changes signed: 0 - tag: v1.004 + tag: v2.000 tag_format: v%v tag_message: v%v Dist::Zilla::Role::Git::Repo: @@ -459,4 +460,4 @@ x_contributors: - 'Dan Book <[email protected]>' - 'Dan Book <[email protected]>' -x_serialization_backend: 'YAML::Tiny version 1.69' +x_serialization_backend: 'YAML::Tiny version 1.70' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/README new/Mojo-SQLite-2.000/README --- old/Mojo-SQLite-1.004/README 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/README 2017-02-11 23:03:56.000000000 +0100 @@ -21,8 +21,16 @@ # Use migrations to drop and recreate the table $sql->migrations->migrate(0)->migrate; - # Insert a few rows + # Get a database handle from the cache for multiple queries my $db = $sql->db; + + # Use SQL::Abstract to generate simple CRUD queries for you + $db->insert('names', {name => 'Isabel'}); + say $db->select('names', ['id'], {name => 'Isabel'})->hash->{id}; + $db->update('names', {name => 'Bel'}, {name => 'Isabel'}); + $db->delete('names', {name => 'Bel'}); + + # Insert a few rows $db->query('insert into names (name) values (?)', 'Sara'); $db->query('insert into names (name) values (?)', 'Stefan'); @@ -123,6 +131,14 @@ my $tempfile = catfile $tempdir, 'test.db'; my $sql = Mojo::SQLite->new->from_filename($tempfile); +EXAMPLES + + This distribution also contains a well-structured example blog + application + <https://github.com/kraih/mojo-pg/tree/master/examples/blog> you can + use for inspiration. This application shows how to apply the MVC design + pattern in practice. + EVENTS Mojo::SQLite inherits all events from Mojo::EventEmitter and can emit @@ -141,6 +157,16 @@ Mojo::SQLite implements the following attributes. + abstract + + my $abstract = $sql->abstract; + $sql = $sql->abstract(SQL::Abstract->new); + + SQL::Abstract object used to generate CRUD queries for + Mojo::SQLite::Database. + + my($stmt, @bind) = $sql->abstract->select('names'); + auto_migrate my $bool = $sql->auto_migrate; @@ -232,7 +258,7 @@ only for short amounts of time. # Add up all the money - say $sql->db->query('select * from accounts') + say $sql->db->select('accounts') ->hashes->reduce(sub { $a->{money} + $b->{money} }); from_filename @@ -307,6 +333,15 @@ $sql->from_string(Mojo::URL->new->scheme('sqlite')->path($filename)->query(sqlite_see_if_its_a_number => 1)); $sql->from_string(URI::file->new($filename)->Mojo::Base::tap(query_form => {PrintError => 1})); +DEBUGGING + + You can set the DBI_TRACE environment variable to get some advanced + diagnostics information printed by DBI. + + DBI_TRACE=1 + DBI_TRACE=15 + DBI_TRACE=SQL + REFERENCE This is the class hierarchy of the Mojo::SQLite distribution. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/cpanfile new/Mojo-SQLite-2.000/cpanfile --- old/Mojo-SQLite-1.004/cpanfile 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/cpanfile 2017-02-11 23:03:56.000000000 +0100 @@ -6,6 +6,7 @@ requires 'File::Temp'; requires 'Mojolicious' => '7.15'; requires 'Scalar::Util'; +requires 'SQL::Abstract' => '1.81'; requires 'URI' => '1.69'; requires 'URI::db' => '0.15'; requires 'URI::file' => '4.21'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/examples/blog/blog.conf new/Mojo-SQLite-2.000/examples/blog/blog.conf --- old/Mojo-SQLite-1.004/examples/blog/blog.conf 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/examples/blog/blog.conf 2017-02-11 23:03:56.000000000 +0100 @@ -1 +1,4 @@ -{sqlite => 'test.db', secrets => ['s3cret']}; +{ + sqlite => 'test.db', + secrets => ['s3cret'], +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/examples/blog/lib/Blog/Model/Posts.pm new/Mojo-SQLite-2.000/examples/blog/lib/Blog/Model/Posts.pm --- old/Mojo-SQLite-1.004/examples/blog/lib/Blog/Model/Posts.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/examples/blog/lib/Blog/Model/Posts.pm 2017-02-11 23:03:56.000000000 +0100 @@ -5,24 +5,24 @@ sub add { my ($self, $post) = @_; - my $db = $self->sqlite->db; - my $sql = 'insert into posts (title, body) values (?, ?)'; - return $db->query($sql, $post->{title}, $post->{body})->last_insert_id; + return $self->sqlite->db->insert('posts', $post)->last_insert_id; } -sub all { shift->sqlite->db->query('select * from posts')->hashes->to_array } +sub all { shift->sqlite->db->select('posts')->hashes->to_array } sub find { my ($self, $id) = @_; - return $self->sqlite->db->query('select * from posts where id = ?', $id)->hash; + return $self->sqlite->db->select('posts', undef, {id => $id})->hash; } -sub remove { shift->sqlite->db->query('delete from posts where id = ?', shift) } +sub remove { + my ($self, $id) = @_; + $self->sqlite->db->delete('posts', {id => $id}); +} sub save { my ($self, $id, $post) = @_; - my $sql = 'update posts set title = ?, body = ? where id = ?'; - $self->sqlite->db->query($sql, $post->{title}, $post->{body}, $id); + $self->sqlite->db->update('posts', $post, {id => $id}); } 1; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Database.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Database.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Database.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Database.pm 2017-02-11 23:03:56.000000000 +0100 @@ -7,10 +7,10 @@ use Mojo::JSON 'to_json'; use Mojo::SQLite::Results; use Mojo::SQLite::Transaction; -use Mojo::Util 'deprecated'; +use Mojo::Util qw(deprecated monkey_patch); use Scalar::Util 'weaken'; -our $VERSION = '1.004'; +our $VERSION = '2.000'; our @CARP_NOT = qw(Mojo::SQLite::Migrations); @@ -23,6 +23,13 @@ }; has results_class => 'Mojo::SQLite::Results'; +for my $name (qw(delete insert select update)) { + monkey_patch __PACKAGE__, lc $name, sub { + my ($self, @cb) = (shift, ref $_[-1] eq 'CODE' ? pop : ()); + return $self->query($self->sqlite->abstract->$name(@_), @cb); + }; +} + sub DESTROY { my $self = shift; @@ -360,8 +367,8 @@ # Insert rows in a transaction eval { my $tx = $db->begin; - $db->query('insert into frameworks values (?)', 'Catalyst'); - $db->query('insert into frameworks values (?)', 'Mojolicious'); + $db->insert('frameworks', {name => 'Catalyst'}); + $db->insert('frameworks', {name => 'Mojolicious'}); $tx->commit; }; say $@ if $@; @@ -371,12 +378,42 @@ C<immediate>. See L<DBD::SQLite/"Transaction and Database Locking"> for more details. +=head2 delete + + my $results = $db->delete($table, \%where); + +Generate a C<DELETE> statement with L<Mojo::SQLite/"abstract"> (usually an +L<SQL::Abstract> object) and execute it with L</"query">. You can also append a +callback for API compatibility with L<Mojo::Pg>; the query is still executed in +a blocking manner. + + $db->delete(some_table => sub { + my ($db, $err, $results) = @_; + ... + }); + Mojo::IOLoop->start unless Mojo::IOLoop->is_running; + =head2 disconnect $db->disconnect; Disconnect L</"dbh"> and prevent it from getting reused. +=head2 insert + + my $results = $db->insert($table, \@values || \%fieldvals, \%options); + +Generate an C<INSERT> statement with L<Mojo::SQLite/"abstract"> (usually an +L<SQL::Abstract> object) and execute it with L</"query">. You can also append a +callback for API compatibility with L<Mojo::Pg>; the query is still executed in +a blocking manner. + + $db->insert(some_table => {foo => 'bar'} => sub { + my ($db, $err, $results) = @_; + ... + }); + Mojo::IOLoop->start unless Mojo::IOLoop->is_running; + =head2 is_listening This method is L<DEPRECATED|Mojo::SQLite::PubSub/"DESCRIPTION">. @@ -428,6 +465,21 @@ $db->query('select ? as foo', {json => {bar => 'I ♥ SQLite!'}}) ->expand(json => 'foo')->hash->{foo}{bar}; +=head2 select + + my $results = $db->select($source, $fields, $where, $order); + +Generate a C<SELECT> statement with L<Mojo::SQLite/"abstract"> (usually an +L<SQL::Abstract> object) and execute it with L</"query">. You can also append a +callback for API compatibility with L<Mojo::Pg>; the query is still executed in +a blocking manner. + + $db->select(some_table => ['foo'] => {bar => 'yada'} => sub { + my ($db, $err, $results) = @_; + ... + }); + Mojo::IOLoop->start unless Mojo::IOLoop->is_running; + =head2 tables my $tables = $db->tables; @@ -445,6 +497,21 @@ This method is L<DEPRECATED|Mojo::SQLite::PubSub/"DESCRIPTION">. +=head2 update + + my $results = $db->update($table, \%fieldvals, \%where); + +Generate an C<UPDATE> statement with L<Mojo::SQLite/"abstract"> (usually an +L<SQL::Abstract> object) and execute it with L</"query">. You can also append a +callback for API compatibility with L<Mojo::Pg>; the query is still executed in +a blocking manner. + + $db->update(some_table => {foo => 'baz'} => {foo => 'bar'} => sub { + my ($db, $err, $results) = @_; + ... + }); + Mojo::IOLoop->start unless Mojo::IOLoop->is_running; + =head1 BUGS Report any issues on the public bugtracker. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Migrations.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Migrations.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Migrations.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Migrations.pm 2017-02-11 23:03:56.000000000 +0100 @@ -8,7 +8,7 @@ use constant DEBUG => $ENV{MOJO_MIGRATIONS_DEBUG} || 0; -our $VERSION = '1.004'; +our $VERSION = '2.000'; has name => 'migrations'; has 'sqlite'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite/PubSub.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite/PubSub.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite/PubSub.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite/PubSub.pm 2017-02-11 23:03:56.000000000 +0100 @@ -5,7 +5,7 @@ use Mojo::Util 'deprecated'; use Scalar::Util 'weaken'; -our $VERSION = '1.004'; +our $VERSION = '2.000'; has [qw(poll_interval sqlite)]; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Results.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Results.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Results.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Results.pm 2017-02-11 23:03:56.000000000 +0100 @@ -5,7 +5,7 @@ use Mojo::JSON 'from_json'; use Mojo::Util 'tablify'; -our $VERSION = '1.004'; +our $VERSION = '2.000'; has 'sth'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Transaction.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Transaction.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite/Transaction.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite/Transaction.pm 2017-02-11 23:03:56.000000000 +0100 @@ -3,7 +3,7 @@ use Carp 'croak'; -our $VERSION = '1.004'; +our $VERSION = '2.000'; has 'db'; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/lib/Mojo/SQLite.pm new/Mojo-SQLite-2.000/lib/Mojo/SQLite.pm --- old/Mojo-SQLite-1.004/lib/Mojo/SQLite.pm 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/lib/Mojo/SQLite.pm 2017-02-11 23:03:56.000000000 +0100 @@ -10,11 +10,13 @@ use Mojo::SQLite::Migrations; use Mojo::SQLite::PubSub; use Scalar::Util 'weaken'; +use SQL::Abstract; use URI; use URI::db; -our $VERSION = '1.004'; +our $VERSION = '2.000'; +has abstract => sub { SQL::Abstract->new(quote_char => '"') }; has 'auto_migrate'; has database_class => 'Mojo::SQLite::Database'; has dsn => sub { _url_from_file(shift->_tempfile)->dbi_dsn }; @@ -141,8 +143,16 @@ # Use migrations to drop and recreate the table $sql->migrations->migrate(0)->migrate; - # Insert a few rows + # Get a database handle from the cache for multiple queries my $db = $sql->db; + + # Use SQL::Abstract to generate simple CRUD queries for you + $db->insert('names', {name => 'Isabel'}); + say $db->select('names', ['id'], {name => 'Isabel'})->hash->{id}; + $db->update('names', {name => 'Bel'}, {name => 'Isabel'}); + $db->delete('names', {name => 'Bel'}); + + # Insert a few rows $db->query('insert into names (name) values (?)', 'Sara'); $db->query('insert into names (name) values (?)', 'Stefan'); @@ -239,6 +249,13 @@ my $tempfile = catfile $tempdir, 'test.db'; my $sql = Mojo::SQLite->new->from_filename($tempfile); +=head1 EXAMPLES + +This distribution also contains a well-structured example +L<blog application|https://github.com/kraih/mojo-pg/tree/master/examples/blog> +you can use for inspiration. This application shows how to apply the MVC design +pattern in practice. + =head1 EVENTS L<Mojo::SQLite> inherits all events from L<Mojo::EventEmitter> and can emit the @@ -257,6 +274,16 @@ L<Mojo::SQLite> implements the following attributes. +=head2 abstract + + my $abstract = $sql->abstract; + $sql = $sql->abstract(SQL::Abstract->new); + +L<SQL::Abstract> object used to generate CRUD queries for +L<Mojo::SQLite::Database>. + + my($stmt, @bind) = $sql->abstract->select('names'); + =head2 auto_migrate my $bool = $sql->auto_migrate; @@ -349,7 +376,7 @@ amounts of time. # Add up all the money - say $sql->db->query('select * from accounts') + say $sql->db->select('accounts') ->hashes->reduce(sub { $a->{money} + $b->{money} }); =head2 from_filename @@ -423,6 +450,15 @@ $sql->from_string(Mojo::URL->new->scheme('sqlite')->path($filename)->query(sqlite_see_if_its_a_number => 1)); $sql->from_string(URI::file->new($filename)->Mojo::Base::tap(query_form => {PrintError => 1})); +=head1 DEBUGGING + +You can set the C<DBI_TRACE> environment variable to get some advanced +diagnostics information printed by L<DBI>. + + DBI_TRACE=1 + DBI_TRACE=15 + DBI_TRACE=SQL + =head1 REFERENCE This is the class hierarchy of the L<Mojo::SQLite> distribution. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/t/00-report-prereqs.dd new/Mojo-SQLite-2.000/t/00-report-prereqs.dd --- old/Mojo-SQLite-1.004/t/00-report-prereqs.dd 2017-01-17 06:10:54.000000000 +0100 +++ new/Mojo-SQLite-2.000/t/00-report-prereqs.dd 2017-02-11 23:03:56.000000000 +0100 @@ -19,6 +19,7 @@ 'File::Spec::Functions' => '0', 'File::Temp' => '0', 'Mojolicious' => '7.15', + 'SQL::Abstract' => '1.81', 'Scalar::Util' => '0', 'URI' => '1.69', 'URI::db' => '0.15', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Mojo-SQLite-1.004/t/crud.t new/Mojo-SQLite-2.000/t/crud.t --- old/Mojo-SQLite-1.004/t/crud.t 1970-01-01 01:00:00.000000000 +0100 +++ new/Mojo-SQLite-2.000/t/crud.t 2017-02-11 23:03:56.000000000 +0100 @@ -0,0 +1,67 @@ +use Mojo::Base -strict; + +BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' } + +use Test::More; +use Mojo::SQLite; +use Mojo::IOLoop; + +my $sql = Mojo::SQLite->new; + +{ + my $db = $sql->db; + $db->query( + 'create table if not exists crud_test ( + id integer primary key autoincrement, + name text + )' + ); + + # Create + $db->insert('crud_test', {name => 'foo'}); + is_deeply $db->select('crud_test')->hashes->to_array, + [{id => 1, name => 'foo'}], 'right structure'; + is $db->insert('crud_test', {name => 'bar'})->last_insert_id, + 2, 'right value'; + is_deeply $db->select('crud_test')->hashes->to_array, + [{id => 1, name => 'foo'}, {id => 2, name => 'bar'}], 'right structure'; + + # Read + is_deeply $db->select('crud_test')->hashes->to_array, + [{id => 1, name => 'foo'}, {id => 2, name => 'bar'}], 'right structure'; + is_deeply $db->select('crud_test', ['name'])->hashes->to_array, + [{name => 'foo'}, {name => 'bar'}], 'right structure'; + is_deeply $db->select('crud_test', ['name'], {name => 'foo'})->hashes->to_array, + [{name => 'foo'}], 'right structure'; + is_deeply $db->select('crud_test', ['name'], undef, {-desc => 'id'}) + ->hashes->to_array, [{name => 'bar'}, {name => 'foo'}], 'right structure'; + + # Non-blocking read + my $result; + my $delay = Mojo::IOLoop->delay(sub { $result = pop->hashes->to_array }); + $db->select('crud_test', $delay->begin); + $delay->wait; + is_deeply $result, [{id => 1, name => 'foo'}, {id => 2, name => 'bar'}], + 'right structure'; + $result = undef; + $delay = Mojo::IOLoop->delay(sub { $result = pop->hashes->to_array }); + $db->select('crud_test', undef, undef, {-desc => 'id'}, $delay->begin); + $delay->wait; + is_deeply $result, [{id => 2, name => 'bar'}, {id => 1, name => 'foo'}], + 'right structure'; + + # Update + $db->update('crud_test', {name => 'baz'}, {name => 'foo'}); + is_deeply $db->select('crud_test', undef, undef, {-asc => 'id'}) + ->hashes->to_array, [{id => 1, name => 'baz'}, {id => 2, name => 'bar'}], + 'right structure'; + + # Delete + $db->delete('crud_test', {name => 'baz'}); + is_deeply $db->select('crud_test', undef, undef, {-asc => 'id'}) + ->hashes->to_array, [{id => 2, name => 'bar'}], 'right structure'; + $db->delete('crud_test'); + is_deeply $db->select('crud_test')->hashes->to_array, [], 'right structure'; +} + +done_testing();
