Perl 6 - the future is here, just unevenly distributed

IRC log for #askriba, 2017-10-22

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
04:04 dboehmer_ joined #askriba
09:17 karjala_ joined #askriba
15:47 karjala_ hi
15:49 karjala_ What's a good way of automatically setting a field (which hasn't been set yet) during creation of a row, to rand(100) ?
15:49 karjala_ I mean, I have a field called "code" that should contain a random number in each row. That number shouldn't change, but it should be set once during creation of the row.
15:50 karjala_ Is this scenario in the documentation somewhere?
15:50 karjala_ I'd like to do my $row = $rs->create({...}) where in ... I do not set the code field explicitly
15:50 karjala_ possible?
15:54 karjala_ I think I found the answer here: https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#Setting-default-values-for-a-row
16:13 ribasushi karjala: rand(100) is likely a terrible idea
16:14 ribasushi karjala_: can you briefly describe what you need this for? sure this isn't a better fit https://en.wikipedia.org/wiki/Universally_unique_identifier ?
16:15 ribasushi karjala_: regarding your original question: what the cookbook lists is one answer
16:15 ribasushi it depends at which stage do you need the value
16:16 karjala I said rand100 for simplicity. In reallity ill create unique alphanum codes for session cookies
16:16 ribasushi you can set it at instantiation ( the new() override ), you can do it right before insertion ( override insert() instead ), you can ask the RDBMS to generate one for you ( usually by using a UUID datatype, and setting retrieve_on_insert so that DBIC brings the id back )
16:16 karjala Crypt::prng
16:17 karjala Ah
16:18 ribasushi karjala: which web framework are you working within?
16:18 karjala Mojolicious
16:21 ribasushi why aren't you simply reusing the already existing infra ( whatever it is, the handling should already exist in the dist )?
16:21 ribasushi i.e. you needing to reach for Crypt{anything} is a very red flag
16:23 ribasushi karjala: I strongly recommend checking back with the manual and/or #mojo whether what you are doing is sensible
16:23 karjala Ok

| Channels | #askriba index | Today | | Search | Google Search | Plain-Text | summary