Created
January 1, 2019 09:32
-
-
Save jonathanstowe/df1ee1ee0bb8d5f3f649da02b5a034a0 to your computer and use it in GitHub Desktop.
Demonstrating round trip interoperability between the Red ORM and JSON::Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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