Navigation Menu

Skip to content

Commit

Permalink
mention PostgreSQL specific extensions specifically
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 27, 2018
1 parent bdc3bd3 commit eed4df0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/Mojo/Pg/Database.pm
Expand Up @@ -279,8 +279,8 @@ L<Mojo::Pg::Transaction/"commit"> has been called before it is destroyed.
my $results = $db->delete($table, \%where, \%options);
Generate a C<DELETE> statement with L<Mojo::Pg/"abstract"> (usually an
L<SQL::Abstract> object) and execute it with L</"query">. You can also append a
callback to perform operations non-blocking.
L<SQL::Abstract::Pg> object) and execute it with L</"query">. You can also
append a callback to perform operations non-blocking.
$db->delete(some_table => sub {
my ($db, $err, $results) = @_;
Expand Down Expand Up @@ -340,8 +340,8 @@ to be used as an operator.
my $results = $db->insert($table, \@values || \%fieldvals, \%options);
Generate an C<INSERT> statement with L<Mojo::Pg/"abstract"> (usually an
L<SQL::Abstract> object) and execute it with L</"query">. You can also append a
callback to perform operations non-blocking.
L<SQL::Abstract::Pg> object) and execute it with L</"query">. You can also
append a callback to perform operations non-blocking.
$db->insert(some_table => {foo => 'bar'} => sub {
my ($db, $err, $results) = @_;
Expand All @@ -350,7 +350,8 @@ callback to perform operations non-blocking.
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
Use all the same argument variations you would pass to the C<insert> method of
L<SQL::Abstract>.
L <SQL::Abstract>
.
# "insert into some_table (foo, baz) values ('bar', 'yada')"
$db->insert('some_table', {foo => 'bar', baz => 'yada'});
Expand All @@ -364,9 +365,13 @@ L<SQL::Abstract>.
# "insert into some_table (foo) values ('bar') returning id, foo"
$db->insert('some_table', {foo => 'bar'}, {returning => ['id', 'foo']});
As well as some PostgreSQL specific extensions added by L<SQL::Abstract::Pg>.
# "insert into some_table (foo) values ('bar') on conflict do nothing"
$db->insert('some_table', {foo => 'bar'}, {on_conflict => \'do nothing'});
Including operations commonly referred to as C<upsert>.
# "insert into some_table (foo) values ('bar')
# on conflict (foo) do update set foo = 'baz'"
$db->insert('some_table', {foo => 'bar'}, {
Expand Down Expand Up @@ -475,8 +480,8 @@ L<Mojo::Promise> object instead of accepting a callback.
my $results = $db->select($source, $fields, $where, \%options);
Generate a C<SELECT> statement with L<Mojo::Pg/"abstract"> (usually an
L<SQL::Abstract> object) and execute it with L</"query">. You can also append a
callback to perform operations non-blocking.
L<SQL::Abstract::Pg> object) and execute it with L</"query">. You can also
append a callback to perform operations non-blocking.
$db->select(some_table => ['foo'] => {bar => 'yada'} => sub {
my ($db, $err, $results) = @_;
Expand All @@ -496,14 +501,16 @@ L<SQL::Abstract>.
# "select * from some_table where foo = 'bar'"
$db->select('some_table', undef, {foo => 'bar'});
# "select * from some_table where foo like '%test%'"
$db->select('some_table', undef, {foo => {-like => '%test%'}});
As well as some PostgreSQL specific extensions added by L<SQL::Abstract::Pg>.
# "select * from some_table where foo = 'bar' order by id desc"
$db->select('some_table', '*', {foo => 'bar'}, {order_by => {-desc => 'id'}});
# "select * from some_table limit 10 offset 20"
$db->select('some_table', undef, undef, {limit => 10, offset => 20});
# "select * from some_table where foo like '%test%'"
$db->select('some_table', undef, {foo => {-like => '%test%'}});
$db->select('some_table', '*', undef, {limit => 10, offset => 20});
# "select * from some_table where foo = 23 group by foo, bar"
$db->select('some_table', '*', {foo => 23}, {group_by => \'foo, bar'});
Expand Down Expand Up @@ -548,8 +555,8 @@ Unsubscribe from a channel, C<*> can be used to unsubscribe from all channels.
my $results = $db->update($table, \%fieldvals, \%where, \%options);
Generate an C<UPDATE> statement with L<Mojo::Pg/"abstract"> (usually an
L<SQL::Abstract> object) and execute it with L</"query">. You can also append a
callback to perform operations non-blocking.
L<SQL::Abstract::Pg> object) and execute it with L</"query">. You can also
append a callback to perform operations non-blocking.
$db->update(some_table => {foo => 'baz'} => {foo => 'bar'} => sub {
my ($db, $err, $results) = @_;
Expand Down
2 changes: 2 additions & 0 deletions lib/SQL/Abstract/Pg.pm
Expand Up @@ -117,6 +117,8 @@ array reference references to pass literal SQL with bind values are supported.
$abstract->insert(
'some_table', {foo => 'bar'}, {on_conflict => \'do nothing'});
This includes operations commonly referred to as C<upsert>.
# "insert into some_table (foo) values ('bar')
# on conflict (foo) do update set foo = 'baz'"
$abstract->insert('some_table', {foo => 'bar'}, {
Expand Down

0 comments on commit eed4df0

Please sign in to comment.