Welcome the channel on the development of Cro, a set of libraries for building reactive distributed systems, lovingly crafted to take advantage of all the Raku Programming Language has to offer (cro.services). This channel is being logged for historical purposes.
Set by lizmat on 24 May 2021.
12:49 TempIRCLogger joined 17:52 melezhik joined
melezhik In cro application I have a connection to mysql db, how can I cache this connection, so not create a db connection on every http request? 17:53
my mysql db ends up with too many connections
sena_kun melezhik, dependency injection I guess, you can create a DB connection at your `service.p6` and then pass it to `routes` as an argument/parameter. 18:20
melezhik so you mean to crate the db connection object inside app.raku file? 18:25
18:40 melezhik left 19:29 melezhik joined
melezhik sena_kun I do this - github.com/melezhik/sparky/blob/ma...b.raku#L19 however simmer like cro does not see my $dbh 19:29
sena_kun melezhik, you can wrap the code to create `$application` into a routine that returns `$application`, and pass the db there. It would be visible in the scope. 19:33
melezhik let me try ... 19:36
sena_kun I've changed as you recommended - github.com/melezhik/sparky/blob/ma....raku#L484  however the very first request to an application works just fine ( data fetched from db and shown in a web page ) however the next request always errors and all cro application becomes unavailable 19:49
I guess this is somehow connected with failure to get dbh for the second time, weird ... 19:50
sena_kun never mind, I have found the cause - github.com/melezhik/sparky/commit/...6b01d41669 )) 19:57
dispose destroys dbh connection, 19:58
sena_kun thanks for your help! 19:59
20:00 melezhik left 20:11 melezhik joined, melezhik left
jnthnwrthngtn Sometimes I wonder if we should explicitly recommend the use of DB:: modules over DBIish in the Cro docs, given those have connection caching built in, which is far safer given the multi-threaded nature of Cro apps 20:28
leont never quite got how the connection caching is supposed to work with prepared statements. They feel rather mutually exclusive. 20:43
jnthnwrthngtn I think for anything you can't do with one of the convenience forms, it's calling the `db` method to explicitly get a handle, which has to have `finish` called on it. 21:49
22:49 melezhik joined
melezhik . 22:49
23:26 melezhik left