Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Илья Рассадин

To clarify Dan's answer about state variables (mostly, for myself).

If you run separate apps in the same process like these.

my $app1 = Test::Mojo->new('MyApp')->app;

my $app2 = Test::Mojo->new('MyApp')->app;

# now $app1->sqlite and $app2->sqlite is the same state variable.

You got two apps in the same process and they share the same state variable.

On 09/05/2019 07:01, Dan Book wrote:
A lexical variable is still bound to a scope, even if it's the file 
scope. If that scope is run again (such as creating another instance 
of the same application) then that will have a separate instance of 
that lexical variable. State variables are initialized once and shared 
between any access for the rest of that process. It can't know what 
outer scope you might have wanted to store it in. It can still be 
useful but you have to make sure that's what you want.


-Dan

On Wed, May 8, 2019 at 11:45 PM Veesh Goldman > wrote:




On Wed, May 8, 2019, 5:55 PM Dan Book mailto:gri...@gmail.com>> wrote:


Alternatively you can use 'state $sqlite = ' inside the helper
but this approach breaks the ability to run multiple separate
apps in the same process, because it will make one $sqlite per
whole process.

-Dan



Could you expound on this problem? I thought state is just a
shortcut to closing over a lexical variable.
-- 
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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit

https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com

.
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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVUWJc-rYw4DhThw9YGcp7OdCh3d0djXRoPLpRkq-vESZg%40mail.gmail.com 
.

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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/e9a40bd8-f099-b2b1-d578-41a22e2b7371%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Dan Book
A lexical variable is still bound to a scope, even if it's the file scope.
If that scope is run again (such as creating another instance of the same
application) then that will have a separate instance of that lexical
variable. State variables are initialized once and shared between any
access for the rest of that process. It can't know what outer scope you
might have wanted to store it in. It can still be useful but you have to
make sure that's what you want.

-Dan

On Wed, May 8, 2019 at 11:45 PM Veesh Goldman  wrote:

>
>
> On Wed, May 8, 2019, 5:55 PM Dan Book  wrote:
>
>>
>> Alternatively you can use 'state $sqlite = ' inside the helper but this
>> approach breaks the ability to run multiple separate apps in the same
>> process, because it will make one $sqlite per whole process.
>>
>> -Dan
>>
>
>
> Could you expound on this problem? I thought state is just a shortcut to
> closing over a lexical variable.
>
> --
> 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 https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com
> 
> .
> 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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVUWJc-rYw4DhThw9YGcp7OdCh3d0djXRoPLpRkq-vESZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Veesh Goldman
On Wed, May 8, 2019, 5:55 PM Dan Book  wrote:

>
> Alternatively you can use 'state $sqlite = ' inside the helper but this
> approach breaks the ability to run multiple separate apps in the same
> process, because it will make one $sqlite per whole process.
>
> -Dan
>


Could you expound on this problem? I thought state is just a shortcut to
closing over a lexical variable.

-- 
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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CAO-W_8CVM9NnBMXuyvHi_FCT7p8%2B11FxTn6it9%3D%3D2JpUr78nfw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] IL PEDOFILO ASSASSINO PAOLO BARRAI FA CRIMINI ANCHE NEL 2019! ORMAI E' CHIARO A TUTTI CHE E' LUI, LA CERNIERA FRA MEGA ASSASSINI DI NDRANGHETA E LA CRIMINALISSIMA ICO EIDOO! E NON DIMENT

2019-05-08 Thread 'ANDREAS NIGG VICE-PRESIDENT SAFRA-SARASIN ZURICH' via Mojolicious
IL PEDOFILO ASSASSINO PAOLO BARRAI FA CRIMINI ANCHE NEL 2019! ORMAI E' 
CHIARO A TUTTI CHE E' LUI, LA CERNIERA FRA MEGA ASSASSINI DI NDRANGHETA E 
LA CRIMINALISSIMA ICO EIDOO! E NON DIMENTICATE CHE STIAMO PARLANDO DI CHI 
E' DEFINITO IN TUTTO IL MONDO.. "PAOLO BARRAI, IL PEDOFILO DEL 
BITCOIN"!

E' UN EFFERATISSIMO, PEDOFILO, ASSASSINO, CRIMINALE PAOLO BARRAI, NATO A 
MILANO IL 28.6.65!
https://twitter.com/megliomortiche1
HA APPENA RICICLATO SOLDI ASSASSINI DI NDRANGHETA IN CRIMINALISSIMO ICO 
EIDOO
https://valori.it/banche-politica-blogger-tutti-gli-affari-dietro-le-cripto-elvetiche/
https://valori.it/chiasso-dove-riciclatori-ndrine-e-criptovalute-sincontrano/
https://www.rsi.ch/la1/programmi/informazione/falo/Bella-gente-10423994.html
https://www.corrieredellacalabria.it/cronaca/item/141842-il-riciclaggio-delle-cosche-in-svizzera-facevano-tutti-cosi/
https://www.ilfattoquotidiano.it/2018/05/17/ndrangheta-e-riciclaggio-in-canton-ticino-cosi-fan-tutti-un-fiduciario-si-confessa-alla-tv-svizzera/4360372/
http://www.areaonline.ch/La-storia-del-fiduciario-ticinese-di-fiducia-della-ndrangheta-29f7ee00
http://ilpunto-borsainvestimenti.blogspot.com/2017/10/cryptopolis-il-debutto-di-un-figlio.html
E' UN LADRO E TRUFFATORE CHE TI AZZERA TUTTI I RISPARMI: PAOLO BARRAI! E' 
UN IDIOTA CHE SBAGLIA, SEMPRE, SEMPRE E STRA SEMPRE IN BORSA: PAOLO BARRAI! 
E' UN NAZISTA, RAZZISTA, KU KLUK KLANISTA, SUPER STRA ANTISEMITA PAOLO 
BARRAI! E' UN PEDOFILO INCULA ED AMMAZZA BAMBINI: PAOLO BARRAI! E' UN 
TERRORISTA DI ESTREMA DESTRA, NONCHE' UNO SPIETATISSIMO ASSASSINO: PAOLO 
BARRAI! ED E' PROTETTO DAI PIU' BASTARDI ASSASSINI NAZISTI SERVIZI SEGRETI, 
TIPO QUELLI DEL FIGLIO DI CANE PEDOFILO E KILLER DONALD TRUMP E NON SOLO... 
NON ABBIAMO NULLA CONTRO GLI USA MA TUTTO CONTRO STO PEZZO DI MERDA 
MAFIOSO, RICICLA SOLDI MAFIOSI, MACCARTISTA, NAZISTA, RAZZISTA, 
KUKLUKKLANISTA, LADRO, TRUFFATORE, DITTATORE CHE E' IL VERME PEDOFILO 
DONALD TRUMP E NE SIAM FIERISSIMI
https://www.vox.com/world/2018/9/12/17764132/trump-fbi-russia-new-york-times-craig-unger
https://www.washingtonpost.com/outlook/trumps-businesses-are-full-of-dirty-russian-money-the-scandal-is-thats-legal/2019/03/29/11b812da-5171-11e9-88a1-ed346f0ec94f_story.html?noredirect=on&utm_term=.ec8f6c557406
https://www.vice.com/en_us/article/ppx7b9/a-brief-history-of-donald-trump-and-the-mafia
https://www.dailymail.co.uk/news/article-3716125/How-Trump-Mob-offer-not-refuse-killing-building-skyscraper-Donald-s-shrewdest-investment-MAFIA.html
https://www.elconfidencial.com/mundo/2019-04-03/donald-trump-siempre-miente-jugando-al-golf_1920226/
https://2.bp.blogspot.com/-LPBPPLwaZ84/WIAPeEY9HCI/MsA/HmIOC-MJiTsECA3dzebwRakgAzLyIU9ugCLcB/s1600/trump%2Band%2Bhooker.jpg
https://whyweprotest.net/attachments/trump-pedophile-one-jpg.259858/
http://www.bubbleofdelusions.com/images/donald-trump-pedophile2.jpg
https://www.newstalk.com/Donald-Trump-accused-of-statutory-rape-assault-and-battery-against-13yearold-girl
https://www.noticiasaominuto.com/mundo/1045873/trump-tera-participado-em-festas-com-muita-cocaina-e-jovens-menores
https://www.fitsnews.com/wp-content/uploads/2017/10/trump-pig-694x1024.jpg )

ED E' TANTO QUANTO UN COCAINOMANE PAZZO E MANIACO FACENTE FILM PORNO 
EFFETTUANDO SESSO ORALE CON CAVALLI: PAOLO PIETRO BARRAI, NATO A MILANO IL 
28.6.1965 ( NON PER NIENTE E' NOTISSIMO IN TUTTO IL MONDO COME " CCC 
CIUCCIA CAZZI DI CAVALLO PAOLO BARRAI")!
https://twitter.com/megliomortiche1/status/1100194746675458048
OLTRE CHE LADRO, TRUFFATORE, SEMPRE FALSO, INCAPACISSIMO IN BORSA, 
AZZERANTE I RISPARMI DI TUTTI E SEMPRE! OLTRE A STRA ESSERE UN 
NAZI-ST-ALKER VIA INTERNET, AIZZATORE DI SUICIDI, MANDANTE DI OMICIDI, E 
TORTURATORE OMICIDA! OLTRE AD ESSERE STATO GIA' "SOLO" 3 VOLTE IN CARCERE" 
( IN UN PRIMO CASO, A SEGUITO DI ENORMI CRIMINALISSIME FRODI CHE EFFETTUAVA 
IN CITIBANK, COME DA FINALE DI QUESTO ARTICOLO 
https://ricerca.repubblica.it/repubblica/archivio/repubblica/2001/02/19/maxi-evasione-da-400-miliardi-terenzio-sotto-torchio.html
PER POI CONOSCERE ALTRA GALERA ANCHE IN BRASILE E PURE PER PEDOFILIA 
OMOSESSUALE
http://www.rotadosertao.com/noticia/10516-porto-seguro-policia-investiga-blogueiro-italiano-suspeito-de-estelionato
http://noticiasdeportoseguro.blogspot.be/2011/03/quem-e-pietro-paolo-barrai.html
http://www.geraldojose.com.br/mobile/?sessao=noticia&cod_noticia=13950
http://www.jornalgrandebahia.com.br/2011/03/policia-civil-de-porto-seguro-investiga-blogueiro-italiano-suspeito-de-estelionato/
http://www.devsuperpage.com/search/Articles.aspx?hl=en&G=23&ArtID=301216
http://www.rotadosertao.com/images/fotos/fotos_noticias/testao.jpg
https://pbs.twimg.com/media/CIB3862WcAA8F7c.png ).
OLTRE AD ESSERE STATO MEGA MULTATO DA CONSOB, PER " APPENA APPENA" 70.000 
EURO, PER MEGA FRODI CHE FACEVA A PROPOSITO DEL FOTOVOLTAICO 
http://www.bluerating.com/banche-e-reti/33345/qmultaq-da-70mila-euro-per-un-ex-promotore-che-ha-violato-gli-obblighi-informativi
http://www.advis

[Mojolicious] Subroutine main::app redefined

2019-05-08 Thread Viktor Nacht
I received the following error using eval to run a helper:

# ./puravida.pl eval 'say app->hashid(1014)'
Subroutine main::app redefined at (eval 601) line 1.

The only change I'm aware of is I updated Mojolicious, but I would assume 
that's the issue, lol. Does this sound like an issue in my code, and if so, 
what would I look for that causes this error?

Thanks!

V

-- 
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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/532c5293-df61-4435-9fa9-cde6be9bc1e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Error handling with Mojo::SQLite

2019-05-08 Thread Dan Book
Testing $@ is not the best way to determine an exception occurred. I'd
recommend Syntax::Keyword::Try as it handles all the edge cases for you,
but otherwise this gets you most of the way:

if (eval { ...; 1 }) {
  # success
} else {
  my $err = $@;
}

And make sure you log errors and rethrow any exceptions you do not handle.
You will want to see the error logging later.

-Dan

On Wed, May 8, 2019 at 1:18 PM Luc Larochelle  wrote:

> This works just as expected. In my case I wanted to catch foreign key
> constraints. Now I'm prepared for the critics, I'll post my "del" route,
> it's from an Lite application serving a web app. I wonder if I'm doing
> things the right way.
>
> I tried to make it idempotent for GET, POST, PUT & DEL but since I have to
> deal with little exceptions in the given routes, they all have their
> definitions. For instance, :id is *id in the GET route, since its principal
> task is to display the whole table. The helpers though (model ?) are not
> dealing with exceptions at all and are used to execute simple tasks to the
> db given the params feeded by the routes.
>
> I'm very opened to discuss all of this, this has to be my most serious
> project since I started using Mojolicious and I'm learning frontend coding
> on-the-fly ...
>
> helper insertOne => sub {
> my ($c,$table) = @_;
> $c->sqlite->db->insert($table, $c->element);
> };
>
>
> helper deleteOne => sub {
>
> my ($c,$table,$param) = @_;
> $c->sqlite->db->delete($table, {$tables->{$table} => $param});
> };
>
>
>
> del '/api/select/:table/:id' => sub {
>
> my $c = shift;
> if ($c->selectOne($c->param('id'))) {
> eval { $c->deleteOne($c->param('table'),$c->param('id')) };
> unless($@) {
> $c->render(status => 200, json => {message => $c->param('id') .
> $messages->{'Del'}});
> } elsif ($@ =~ /FOREIGN KEY constraint failed/) {
> $c->render(status => 400, json => {message => $c->param('id') .
> $messages->{'FK'}});
> }
> } else {
> $c->render(status => 404, json => {message => "Not found"});
> }
>
> };
>
>
>
> On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote:
>>
>> Thanks ! Maybe I read only the sections and bold titles :)
>>
>> I'll have a second look.
>>
>>
>> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote:
>>>
>>> As mentioned in the documentation: "Any database errors will throw an
>>> exception as RaiseError is automatically enabled, so use eval or
>>> Try::Tiny  to catch them. "
>>>
>>> This is the standard way to handle errors in Perl. Syntax::Keyword::Try
>>> is also a nicer interface if you can use keyword plugins (perl 5.14+).
>>>
>>> -Dan
>>>
>>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle 
>>> wrote:
>>>
 Hello Veesh, well to me that looks like "eval" , right ? I meant is
 there a way with Mojo::SQLite to check errors ?

 On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:
>
> Does Try::Tiny strike your fancy? It'll put the error into $_ in the
> catch block.
>
> Short of that, I'm fairly certain it'll crash your thread if it fails.
>
> On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle 
> wrote:
>
>> Hello everyone,
>>
>> While a 'select' statement can be double checked by the presence of
>> the returned data, how can I confirm that statements such as 'insert' ,
>> 'update' or 'delete' are successful ?
>>
>> For instance, using SQL::Abstract and some helpers
>>
>> helper insertOne => sub {
>> my ($c,$table) = @_;
>> $c->sqlite->db->insert($table, $c->element);
>> };
>>
>>
>>
>> I've seen in the documentation that one could *eval* and look into
>> $@ , but is there a more "inline" way to do this ?
>>
>> Cheers !
>>
>> Luc
>>
>> --
>> 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...@googlegroups.com.
>> To post to this group, send email to mojol...@googlegroups.com.
>> Visit this group at https://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...@googlegroups.com.
 To post to this group, send email to mojol...@googlegroups.com.
 Visit this group at https://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@googleg

Re: [Mojolicious] Error handling with Mojo::SQLite

2019-05-08 Thread Luc Larochelle
This works just as expected. In my case I wanted to catch foreign key 
constraints. Now I'm prepared for the critics, I'll post my "del" route, 
it's from an Lite application serving a web app. I wonder if I'm doing 
things the right way.

I tried to make it idempotent for GET, POST, PUT & DEL but since I have to 
deal with little exceptions in the given routes, they all have their 
definitions. For instance, :id is *id in the GET route, since its principal 
task is to display the whole table. The helpers though (model ?) are not 
dealing with exceptions at all and are used to execute simple tasks to the 
db given the params feeded by the routes.

I'm very opened to discuss all of this, this has to be my most serious 
project since I started using Mojolicious and I'm learning frontend coding 
on-the-fly ... 

helper insertOne => sub {
my ($c,$table) = @_;
$c->sqlite->db->insert($table, $c->element);
};


helper deleteOne => sub {

my ($c,$table,$param) = @_;
$c->sqlite->db->delete($table, {$tables->{$table} => $param});
};



del '/api/select/:table/:id' => sub {

my $c = shift;
if ($c->selectOne($c->param('id'))) {
eval { $c->deleteOne($c->param('table'),$c->param('id')) };
unless($@) {
$c->render(status => 200, json => {message => $c->param('id') . 
$messages->{'Del'}});
} elsif ($@ =~ /FOREIGN KEY constraint failed/) {
$c->render(status => 400, json => {message => $c->param('id') . 
$messages->{'FK'}});
}
} else { 
$c->render(status => 404, json => {message => "Not found"});
}

};

 

On Wednesday, 20 March 2019 11:58:04 UTC-4, Luc Larochelle wrote:
>
> Thanks ! Maybe I read only the sections and bold titles :)
>
> I'll have a second look.
>
>
> On Monday, 18 March 2019 12:35:48 UTC-4, Dan Book wrote:
>>
>> As mentioned in the documentation: "Any database errors will throw an 
>> exception as RaiseError is automatically enabled, so use eval or 
>> Try::Tiny  to catch them. "
>>
>> This is the standard way to handle errors in Perl. Syntax::Keyword::Try 
>> is also a nicer interface if you can use keyword plugins (perl 5.14+).
>>
>> -Dan
>>
>> On Mon, Mar 18, 2019 at 10:00 AM Luc Larochelle  
>> wrote:
>>
>>> Hello Veesh, well to me that looks like "eval" , right ? I meant is 
>>> there a way with Mojo::SQLite to check errors ?
>>>
>>> On Saturday, 16 March 2019 15:12:11 UTC-4, Veesh Goldman wrote:

 Does Try::Tiny strike your fancy? It'll put the error into $_ in the 
 catch block.

 Short of that, I'm fairly certain it'll crash your thread if it fails.

 On Fri, Mar 15, 2019, 10:22 PM Luc Larochelle  
 wrote:

> Hello everyone,
>
> While a 'select' statement can be double checked by the presence of 
> the returned data, how can I confirm that statements such as 'insert' , 
> 'update' or 'delete' are successful ?
>
> For instance, using SQL::Abstract and some helpers
>
> helper insertOne => sub {
> my ($c,$table) = @_;
> $c->sqlite->db->insert($table, $c->element);
> };
>
>
>
> I've seen in the documentation that one could *eval* and look into $@ 
> , but is there a more "inline" way to do this ?
>
> Cheers !
>
> Luc
>
> -- 
> 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...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at https://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...@googlegroups.com.
>>> To post to this group, send email to mojol...@googlegroups.com.
>>> Visit this group at https://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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/e3480fbb-d830-461f-b644-33f3de62db18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Luc Larochelle
Hello Dan, thank you so much. 

Now I guess I'll have to deal with error management but you already showed 
me the way in that other post :)

https://groups.google.com/forum/#!topic/mojolicious/Tfv8RK2UkrI

Cheers !

On Wednesday, 8 May 2019 10:55:14 UTC-4, Dan Book wrote:
>
> This is the correct way to set the pragma for each connection. However 
> your helper is not set up right. You are creating a new Mojo::SQLite object 
> each time it is called and so the on-connection handler is no longer 
> applied. You need to declare 'my $sqlite;' outside and only set it in the 
> helper if it's not defined yet.
>
> my $sqlite;
> helper sqlite => sub { $sqlite //= Mojo::SQLite->new... };
>
> Alternatively you can use 'state $sqlite = ' inside the helper but this 
> approach breaks the ability to run multiple separate apps in the same 
> process, because it will make one $sqlite per whole process.
>
> -Dan
>
> On Wed, May 8, 2019 at 10:47 AM Luc Larochelle  > wrote:
>
>> Hello everyone,
>>
>> I've been struggling with this one for a while, so I decided to post here.
>>
>> I built a crud web application to manage hosts configuration for a 
>> backend backup application.
>>
>> There is a parent table (Devices) , which relates to child tables by name 
>> (authName , promptName ...). I defined foreign keys constraint where delete 
>> of a child is restricted (if the child is used in the parent table).
>>
>> Problem is, foreign keys do not seem to be effective from the web app. If 
>> I open a connection to the db from the cli and enable PRAGMA foreign_keys = 
>> ON; before attempting a delete, I received the appropriate response 
>>
>> sqlite> delete from Auths where authName = "myAuth";
>> Error: foreign key constraint failed
>>
>> Even if it's being defined in my schema, it's not working. 
>>
>> So I searched the forums for an answer. One good solution was to have the 
>> PRAGMA defined in ~/.sqliterc, but this is working only for the user. 
>>
>> Finally someone said it had to be applied at each connection, so I added 
>> the call " on connection " to send the command every time, still no luck.
>>
>> Below is the relevant piece of code for discussion, can someone please 
>> point out what's wrong with my approach ?
>>
>>
>>
>>
>> helper sqlite => sub {my $sql = Mojo::SQLite->new('sqlite:mynewdb2.db')};
>>
>>
>> app->sqlite->on(connection => sub {
>> my ($sql, $dbh) = @_;
>> $dbh->do('PRAGMA foreign_keys = ON');
>> });
>>
>>
>>
>> app->sqlite->auto_migrate(1)->migrations->name('ConfigMgt')->from_string(<> -- 1 up
>> PRAGMA foreign_keys = ON;
>>
>> create  table  if not exists  Devices 
>> (
>>   hostname  text  ,
>>   ipaddress  text  ,
>>   groupName  text  ,
>>   authName  text  ,
>>   connectionName  text  ,
>>   promptName  text  ,
>>   ignoreStatus  int  default 0,
>>   dateAdd  datetime  ,
>>   dateMod  datetime  , 
>>   primary key (hostname, ipaddress),
>>   constraint deviceAuth foreign key (authName)references Auths(authName) 
>> on delete restrict  on update no action ,
>>   constraint deviceScript foreign key (groupName)references 
>> Scripts(scriptName) on delete restrict  on update no action ,
>>   constraint devicePrompt foreign key (promptName)references 
>> Prompts(promptName) on delete restrict  on update no action ,
>>   constraint deviceConnection foreign key (connectionName)references 
>> Connections(connectionName) on delete restrict  on update no action 
>> );
>>
>>
>>
>>
>> -- 
>> 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 mojol...@googlegroups.com .
>> To post to this group, send email to mojol...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/mojolicious.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/mojolicious/f8d536f2-4ea7-4447-9b8e-04cc639bb287%40googlegroups.com
>>  
>> 
>> .
>> 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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/4255e2b4-1e39-4242-8bb7-0e7836ccc8d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Dan Book
This is the correct way to set the pragma for each connection. However your
helper is not set up right. You are creating a new Mojo::SQLite object each
time it is called and so the on-connection handler is no longer applied.
You need to declare 'my $sqlite;' outside and only set it in the helper if
it's not defined yet.

my $sqlite;
helper sqlite => sub { $sqlite //= Mojo::SQLite->new... };

Alternatively you can use 'state $sqlite = ' inside the helper but this
approach breaks the ability to run multiple separate apps in the same
process, because it will make one $sqlite per whole process.

-Dan

On Wed, May 8, 2019 at 10:47 AM Luc Larochelle 
wrote:

> Hello everyone,
>
> I've been struggling with this one for a while, so I decided to post here.
>
> I built a crud web application to manage hosts configuration for a backend
> backup application.
>
> There is a parent table (Devices) , which relates to child tables by name
> (authName , promptName ...). I defined foreign keys constraint where delete
> of a child is restricted (if the child is used in the parent table).
>
> Problem is, foreign keys do not seem to be effective from the web app. If
> I open a connection to the db from the cli and enable PRAGMA foreign_keys =
> ON; before attempting a delete, I received the appropriate response
>
> sqlite> delete from Auths where authName = "myAuth";
> Error: foreign key constraint failed
>
> Even if it's being defined in my schema, it's not working.
>
> So I searched the forums for an answer. One good solution was to have the
> PRAGMA defined in ~/.sqliterc, but this is working only for the user.
>
> Finally someone said it had to be applied at each connection, so I added
> the call " on connection " to send the command every time, still no luck.
>
> Below is the relevant piece of code for discussion, can someone please
> point out what's wrong with my approach ?
>
>
>
>
> helper sqlite => sub {my $sql = Mojo::SQLite->new('sqlite:mynewdb2.db')};
>
>
> app->sqlite->on(connection => sub {
> my ($sql, $dbh) = @_;
> $dbh->do('PRAGMA foreign_keys = ON');
> });
>
>
>
> app->sqlite->auto_migrate(1)->migrations->name('ConfigMgt')->from_string(< -- 1 up
> PRAGMA foreign_keys = ON;
>
> create  table  if not exists  Devices
> (
>   hostname  text  ,
>   ipaddress  text  ,
>   groupName  text  ,
>   authName  text  ,
>   connectionName  text  ,
>   promptName  text  ,
>   ignoreStatus  int  default 0,
>   dateAdd  datetime  ,
>   dateMod  datetime  ,
>   primary key (hostname, ipaddress),
>   constraint deviceAuth foreign key (authName)references Auths(authName)
> on delete restrict  on update no action ,
>   constraint deviceScript foreign key (groupName)references
> Scripts(scriptName) on delete restrict  on update no action ,
>   constraint devicePrompt foreign key (promptName)references
> Prompts(promptName) on delete restrict  on update no action ,
>   constraint deviceConnection foreign key (connectionName)references
> Connections(connectionName) on delete restrict  on update no action
> );
>
>
>
>
> --
> 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 https://groups.google.com/group/mojolicious.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mojolicious/f8d536f2-4ea7-4447-9b8e-04cc639bb287%40googlegroups.com
> 
> .
> 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 https://groups.google.com/group/mojolicious.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mojolicious/CABMkAVX2g1rX5vf9-QCrs-X0GH5h%3D-GNFHrJ1BpGp59KQsHnVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Mojolicious] Mojo::SQLite && foreign keys support ?

2019-05-08 Thread Luc Larochelle
Hello everyone,

I've been struggling with this one for a while, so I decided to post here.

I built a crud web application to manage hosts configuration for a backend 
backup application.

There is a parent table (Devices) , which relates to child tables by name 
(authName , promptName ...). I defined foreign keys constraint where delete 
of a child is restricted (if the child is used in the parent table).

Problem is, foreign keys do not seem to be effective from the web app. If I 
open a connection to the db from the cli and enable PRAGMA foreign_keys = 
ON; before attempting a delete, I received the appropriate response 

sqlite> delete from Auths where authName = "myAuth";
Error: foreign key constraint failed

Even if it's being defined in my schema, it's not working. 

So I searched the forums for an answer. One good solution was to have the 
PRAGMA defined in ~/.sqliterc, but this is working only for the user. 

Finally someone said it had to be applied at each connection, so I added 
the call " on connection " to send the command every time, still no luck.

Below is the relevant piece of code for discussion, can someone please 
point out what's wrong with my approach ?




helper sqlite => sub {my $sql = Mojo::SQLite->new('sqlite:mynewdb2.db')};


app->sqlite->on(connection => sub {
my ($sql, $dbh) = @_;
$dbh->do('PRAGMA foreign_keys = ON');
});


app->sqlite->auto_migrate(1)->migrations->name('ConfigMgt')->from_string(