Advertisement
Guest User

Mojo::Pg abstract update returning

a guest
Jun 5th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use feature 'say';
  7.  
  8. use Mojo::Pg;
  9.  
  10. # Use a PostgreSQL connection string for configuration
  11. my $pg = Mojo::Pg->new('postgresql://localhost/testdb');
  12.  
  13. $pg->migrations->name('my_names_app')->from_string(<<EOF)->migrate;
  14. -- 1 up
  15. create table names (id serial primary key, name text);
  16. -- 1 down
  17. drop table names;
  18. EOF
  19.  
  20. # insert a name
  21. my $id = $pg->db->insert('names', { name => 'Fred Johnson' }, { returning => 'id' })->hash->{id};
  22. say "Insert id is $id";
  23.  
  24. # update it, returning it
  25. say $pg->db->update('names', { name => 'Anderson Dawes' }, { id => $id }, { returning => 'name' })->hash->{name};
  26.  
  27. ----
  28.  
  29. Insert id is 16
  30. DBD::Pg::st fetchrow_hashref failed: no statement executing at /Users/justin/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Mojo/Pg/Results.pm line 22.
  31.  
  32. ----
  33.  
  34. $ DBI_TRACE=1 perl returning.pl 2> >(grep prepare)
  35. <- prepare_cached('select version from mojo_migrations where name = $1', HASH(0x7fb93621dad8), ...)= ( DBI::st=HASH(0x7fb9376db7d0) ) [1 items] at Database.pm line 86
  36. <- prepare_cached('INSERT INTO "names" ( "name") VALUES ( ? ) RETURNING "id"', HASH(0x7fb93621dad8), ...)= ( DBI::st=HASH(0x7fb9376dbfe0) ) [1 items] at Database.pm line 86
  37. Insert id is 17
  38. <- prepare_cached('UPDATE "names" SET "name" = ? WHERE ( "id" = ? )', HASH(0x7fb93621dad8), ...)= ( DBI::st=HASH(0x7fb9376e6920) ) [1 items] at Database.pm line 86
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement