Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created January 1, 2019 09:32
Show Gist options
  • Save jonathanstowe/df1ee1ee0bb8d5f3f649da02b5a034a0 to your computer and use it in GitHub Desktop.
Save jonathanstowe/df1ee1ee0bb8d5f3f649da02b5a034a0 to your computer and use it in GitHub Desktop.
Demonstrating round trip interoperability between the Red ORM and JSON::Class
use JSON::Class;
use Red;
model Foo is table('foo') does JSON::Class {
has Int $.id is serial;
has Str $.name is column;
}
my $*RED-DEBUG = $_ with %*ENV<RED_DEBUG>;
my $*RED-DEBUG-RESPONSE = $_ with %*ENV<RED_DEBUG_RESPONSE>;
my $*RED-DB = database "SQLite", |(:database($_) with %*ENV<RED_DATABASE>);
Foo.^create-table;
my $foo = Foo.^create( name => 'Blah');
my $j = $foo.to-json;
say $j;
$j ~~ s/Blah/Woof/;
my $new-foo = Foo.from-json($j);
$new-foo.^save;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment