Group
Extension

Matches 7

DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Schema/ResultAs/Json.pm ( view source; MetaCPAN )
::DataModel::Schema::ResultAs::Json;
#----------------------------------------------------------------------
use warnings;
use strict;
use DBIx::DataModel::Carp;
use JSON::MaybeXS     ();

use parent 
odel::Schema::ResultAs';

use namespace::clean;

sub new {
  my ($class, %json_options) = @_;
  keys %json_options
    or %json_options = ( pretty          => 1,
                         allow_blessed
s \%json_options, $class;
}


sub get_result {
  my ($self, $statement) = @_;

  my $json_maker = JSON::MaybeXS->new(%$self);
  my $json       = $json_maker->encode($statement->all);
  return $json;
}
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Doc/Design.pod ( view source; MetaCPAN )
the whole datastructure to external
helper modules such as XML generators, Perl dumps, javascript JSON,
templates of the Template Toolkit, etc. Such modules need to walk on
the data tree, exploring ke
 encapsulation.

=item *

row hashrefs can be converted directly to import/export formats
such as JSON, YAML, XML, etc.

=back

Of course the hash API also has some disadvantages : it is not
possible 
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Doc/Cookbook.pod ( view source; MetaCPAN )
s can often be ignored; but nevertheless they can be a problem
with some external modules like L<JSON> that croak when encoding
a blessed reference. In that case you can use the C<unbless()> functio
essing is
recursively applied to nested datastructures :

  $schema->unbless($rows);
  my $json = JSON->new->encode($rows);


=head2 Common table expressions (WITH RECURSIVE)

The SQL syntax 
ONVERSION

=head2 JSON

  use JSON;
  my $json_converter = JSON->new->convert_blessed(1);
  my $json_text      = $json_converter->encode($data_row);

By default, the L<JSON> module refuses to 
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Source.pm ( view source; MetaCPAN )
y one field '__schema'
  my @k = keys %$self;
  return @k == 1 && $k[0] eq '__schema';
}


sub TO_JSON {
  my $self = shift;
  my $clone = {%$self};
  delete $clone->{__schema};
  return $clone;
}


1
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Doc/Delta_v3.pod ( view source; MetaCPAN )
rayref>

=item L<Hashref|DBIx::DataModel::Schema::ResultAs::Hashref>

=item L<Json|DBIx::DataModel::Schema::ResultAs::Json>

=item L<Rows|DBIx::DataModel::Schema::ResultAs::Rows>

=item L<Sql|DBIx::Da
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel/Doc/Reference.pod ( view source; MetaCPAN )
me]);


Writes all rows into an Excel file.


=item L<json|DBIx::DataModel::Schema::ResultAs::Json>

Converts all rows to JSON format, using L<JSON::MaybeXS>.

=item L<yaml|DBIx::DataModel::Schema::Re
.

=head3 TO_JSON

  use JSON;
  my $json_converter = JSON->new->convert_blessed(1);
  my $json_text      = $json_converter->encode($data_row);

The C<Source> class implements a C<TO_JSON> method, so 
e easily converted into JSON strings
(including nested rows that may have been added by the L</expand> method).
See L<JSON/convert_blessed> for more explanations.

The C<TO_JSON> method merely copies 
DBIx-DataModel ( D/DA/DAMI/DBIx-DataModel-3.14.tar.gz, DAMI, 2025; MetaCPAN )
DBIx-DataModel/lib/DBIx/DataModel.pm ( view source; MetaCPAN )
# export as PerlDump
  use XML::Simple;  print XMLout ($export); # export as XML
  use JSON;         print to_json($export); # export as Javascript
  use YAML;         print Dump   ($export); # export
something_immediately_with($row);
  }


=head3 Other kinds of results

  my $json = $source->select(..., -result_as => 'json');
  my $yaml = $source->select(..., -result_as => 'yaml');
  my $tree = $s

Powered by Groonga
Maintained by Kenichi Ishigaki <ishigaki@cpan.org>. If you find anything, submit it on GitHub.