{"id":16310151,"url":"https://github.com/grinnz/mojo-db-results-role-struct","last_synced_at":"2025-04-13T17:13:23.883Z","repository":{"id":56838231,"uuid":"209851068","full_name":"Grinnz/Mojo-DB-Results-Role-Struct","owner":"Grinnz","description":"Mojo::DB::Results::Role::Struct - Database query results as structs","archived":false,"fork":false,"pushed_at":"2021-06-17T02:58:04.000Z","size":41,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T17:13:20.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Mojo::DB::Results::Role::Struct","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Grinnz.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-20T17:58:21.000Z","updated_at":"2021-06-17T02:58:07.000Z","dependencies_parsed_at":"2022-09-10T03:32:00.838Z","dependency_job_id":null,"html_url":"https://github.com/Grinnz/Mojo-DB-Results-Role-Struct","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-DB-Results-Role-Struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-DB-Results-Role-Struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-DB-Results-Role-Struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-DB-Results-Role-Struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Grinnz","download_url":"https://codeload.github.com/Grinnz/Mojo-DB-Results-Role-Struct/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750127,"owners_count":21155687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T21:23:56.439Z","updated_at":"2025-04-13T17:13:23.864Z","avatar_url":"https://github.com/Grinnz.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=head1 NAME\n\nMojo::DB::Results::Role::Struct - Database query results as structs\n\n=head1 SYNOPSIS\n\n  use Mojo::SQLite;\n  my $sqlite = Mojo::SQLite-\u003enew(...);\n  my $results = $sqlite-\u003edb-\u003equery('SELECT * FROM \"table\" WHERE \"foo\" = ?', 42);\n  my $struct = $results-\u003ewith_roles('Mojo::DB::Results::Role::Struct')-\u003estructs-\u003efirst;\n  my $bar = $struct-\u003ebar; # dies unless column \"bar\" exists\n\n  use Mojo::Pg;\n  my $pg = Mojo::Pg-\u003enew(...)-\u003ewith_roles('Mojo::DB::Role::ResultsRoles');\n  push @{$pg-\u003eresults_roles}, 'Mojo::DB::Results::Role::Struct';\n  my $results = $pg-\u003edb-\u003equery('SELECT \"foo\", \"bar\" FROM \"table\"');\n  foreach my $row ($results-\u003estructs-\u003eeach) {\n    my $foo = $row-\u003efoo;\n    my $bar = $row-\u003ebaz; # dies\n  }\n\n=head1 DESCRIPTION\n\nThis role can be applied to a results object for L\u003cMojo::Pg\u003e or similar\ndatabase APIs. It provides L\u003c/\"struct\"\u003e and L\u003c/\"structs\"\u003e methods which return\nL\u003cStruct::Dumb\u003e records, providing read-only accessors only for the expected\ncolumn names. Note that a column name that is not a valid identifier is\ntrickier to access in this manner.\n\n  my $row = $results-\u003estruct;\n  my $col_name = 'foo.bar';\n  my $val = $row-\u003e$col_name;\n  # or\n  my $val = $row-\u003e${\\'foo.bar'};\n\nYou can apply the role to a results object using L\u003cMojo::Base/\"with_roles\"\u003e,\nor apply it to all results objects created by a database manager using\nL\u003cMojo::DB::Role::ResultsRoles\u003e as shown in the synopsis.\n\n=head1 METHODS\n\nL\u003cMojo::DB::Results::Role::Struct\u003e composes the following methods.\n\n=head2 struct\n\n  my $struct = $results-\u003estruct;\n\nFetch next row from the statement handle with the result object's C\u003carray\u003e\nmethod, and return it as a struct.\n\n=head2 structs\n\n  my $collection = $results-\u003estructs;\n\nFetch all rows from the statement handle with the result object's C\u003carrays\u003e\nmethod, and return them as a L\u003cMojo::Collection\u003e object containing structs.\n\n=head1 BUGS\n\nReport any issues on the public bugtracker.\n\n=head1 AUTHOR\n\nDan Book \u003cdbook@cpan.org\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is Copyright (c) 2019 by Dan Book.\n\nThis is free software, licensed under:\n\n  The Artistic License 2.0 (GPL Compatible)\n\n=head1 SEE ALSO\n\nL\u003cMojo::DB::Role::ResultsRoles\u003e, L\u003cMojo::Pg\u003e, L\u003cMojo::SQLite\u003e, L\u003cMojo::mysql\u003e\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrinnz%2Fmojo-db-results-role-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrinnz%2Fmojo-db-results-role-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrinnz%2Fmojo-db-results-role-struct/lists"}