[Mojolicious] Re: Mojo::Pg

2014-10-12 Thread sri
Funny thing, finding a good pattern for transaction management was actually 
harder than implementing migrations. The problem is that with RaiseError 
the $db object goes out of scope and puts the database handle, which looks 
fine, back into the connection cache with a transaction that's still in 
progress. So what i ended up with is the transaction scope guard approach 
from DBIx::Class, which as it turns out, works extremely well with async 
queries as well.

  # Commit
  {
my $tx = $db->begin;
$db->query('insert into foo values (?)', 'one');
$db->query('insert into foo values (?)', 'two');
$tx->commit;
  };

 If $tx goes out of scope before $tx->commit has been called, it will 
trigger a rollback, super simple.

  # Rollback
  {
my $tx = $db->begin;
$db->query('insert into foo values (?)', 'one');
$db->query('insert into foo values (?)', 'two');
  };

This is the latest addition in Mojo::Pg 0.07, which i've just released.

--
sebastian

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojo::Pg

2014-10-12 Thread sri

>
> Windows 8
> Perl : (v5.16.3, MSWin32)
> Mojolicious : 5.49
> Mojo-Pg : 0.06
>


Could be a Windows problem, it works fine for me on OS X.

--
sebastian 

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Re: Mojo::Pg

2014-10-12 Thread Paolo Saudin
Hi,
I'm trying this module but I get an error on the non-blocking sample, while
the other methods works fine :

# Select all rows non-blocking
Mojo::IOLoop->delay(
  sub {
my $delay = shift;
$db->query('select * from names' => $delay->begin);
  },
  sub {
my ($delay, $err, $results) = @_;
$results->hashes->pluck('name')->join("\n")->say;
  }
)->wait;

Mojo::Reactor::Poll: Timer be5d85eb26e795680ba9a94d8d356dcc failed: Can't
use an undefined value as a symbol reference at
C:/Perl64/site/lib/Mojo/Reactor/Poll.pm line 16.


Windows 8
Perl : (v5.16.3, MSWin32)
Mojolicious : 5.49
Mojo-Pg : 0.06

Is there something I am doing wrong ?
regards
paolo saudin


2014-10-11 0:57 GMT+02:00 sri :

> P.S.: And before anyone asks... nope there is no chance they will go into
>> a separate distribution and become database agnostic, i'm using PostgreSQL
>> features quite extensively.
>>
>
> P.P.S: PostgreSQL totally rocks! :)
>
> --
> sebastian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious+unsubscr...@googlegroups.com.
> To post to this group, send email to mojolicious@googlegroups.com.
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Mojo::UserAgent - Preserve the order of POST parameters

2014-10-12 Thread blueCat1301
Hi,

Just a suggestion based on my recent struggle using Mojo::UserAgent to post 
some data. There are web sites that count on specific POST parameter order. 
All browsers send application/x-www-form-urlencoded data in tree order 
, preserving a 
specific order of parameters as defined in DOM.

Just using
$tx = $ua->post($url => form => { b => 'param_1',  a => 'param_2' } );

will generate a request like:
 a=param_2&b=param_1

because the form generator sorts the keys of the hash. There is no simply 
way to generate a request like
 b=param_1&a=param_2
except building the Mojo::Parameters and Transactor manually.

May be you could just add the option to do:
$tx = $ua->post($url => form => [ b => 'param_1',  a => 'param_2' ] );

using an array reference instead of a hash one.

I am just a Mojo newbie, but I would dare to suggest :-) that replacing 
line 175 in Mojo::UserAgent::Transactor
my $p = Mojo::Parameters->new(map { $_ => $form->{$_} } sort keys %$form);

with something like:
my $p;
if ( ref $form eq 'HASH' ) { 
$p = Mojo::Parameters->new(map { $_ => $form->{$_} } sort keys %$form);
} else {
$p = Mojo::Parameters->new(@$form);
}

would do the trick.


Thank you.


-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Re: Mojo::mysql

2014-10-12 Thread Jan Henning Thorsen
Quick: Yeah, it was easy to make, since you had done all the hard work 
Sebastian :-)

Step 1: Search and replace (pg|postgres) with mysql
Step 
2: 
https://github.com/jhthorsen/mojo-mysql/commit/f67f48c4b97176275e50b52b66355338f0c70f9d
Step 
3: 
https://github.com/jhthorsen/mojo-mysql/commit/9a5fbc619a20ad5db25cdbced7c4f852a6be21de

About step #3. I'm not sure if what I'm doing there is a hack or not. Any 
MySQL people out there that can comment on this? The fix to make UTF8 work 
is to both set the "mysql_enable_utf8" and make sure the table has "COLLATE 
= utf8_bin". Is the way to store/read UTF8 from MySQL?

I suggest others to follow the same steps, if it's possible for other DBD 
drivers. It's nice to have the same API - especially when the API makes 
sense. I was looking at SQLite, but couldn't find any async support. I'm a 
bit surprised, since it's a file on disk... (Let's open a new thread if 
someone wants to make discuss this further)


On Saturday, October 11, 2014 10:49:42 PM UTC+2, sri wrote:
>
> Today I release Mojo::mysql, a fork of Sebastian's Mojo::Pg which allow 
>> you to use the same API, but against the MySQL database.
>>
>>   https://metacpan.org/release/JHTHORSEN/Mojo-mysql-0.01
>>
>
> Yay, that was quick!
>  
>
>> I'm also unsure if I will add migration support to Mojo::mysql, even if 
>> Mojo::Pg gets migrations support. I will however (most probably) accept 
>> pull requests for this feature.
>>
>
> Yea, i think you're better off not implementing migrations, MySQL lacks 
> support for transactional ddl, which is what makes migrations for 
> PostgreSQL so awesome. Yesterday i was still a bit unsure if migrations are 
> going to stay in Mojo::Pg, but the ability to have your database schema 
> sync automatically and safely on startup is just too good. So they will say.
>
> --
> sebastian
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.