-
-
Save Skarsnik/ea16c3d9b305bed0f536 to your computer and use it in GitHub Desktop.
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 QDORM; | |
class Author is rw { | |
has Int $.id; #= qdb:primarykey | |
has Str $.name; | |
} | |
class Chapter is rw { | |
has Int $.id; #= qdb:primarykey | |
has Str $.title; | |
has Int $.words; | |
} | |
class Story is rw { | |
has Int $.id; #= qdb:primarykey | |
has Str $.title; | |
has Author $.author; | |
has Str @.tags; #= qdb:pgarray | |
has Chapter @.chapters; #= qdb:card=1 | |
} | |
class Bookshelf is rw { | |
has Int $.id; #= qdb:primarykey | |
has Str $.name; | |
has Story @.stories; | |
} | |
my $con = DBConnection.new(:driver("Pg")); | |
say "== HELO =="; | |
class StorableStory is Story does QDBStorable { | |
} | |
my StorableStory $s; | |
#Table Creation | |
qdorm-create-table(Bookshelf); | |
#Load from DB | |
$s.new-from-db(42); | |
#Delete | |
$s.db-delete(); | |
my $s1 = Story.new; | |
$s1 does QDBStorable; | |
#Save to DB | |
$s1.db-save(); | |
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
root@testperl6:~/piko/qdorm# perl6 -I lib/ example.p6 | |
== HELO == | |
-----CREATE Bookshelf---- | |
--Array | |
--Do something | |
--Array | |
--Array | |
--Do something | |
-----CREATE Story---- | |
-----CREATE Author---- | |
Create TABLE Author( | |
id Int PRIMARY KEY , | |
name varchar(255) | |
); | |
-----CREATE Chapter---- | |
Create TABLE Chapter( | |
id Int PRIMARY KEY , | |
title varchar(255), | |
words Int, | |
story_id Int REFERENCES Story(id) | |
); | |
Create TABLE Story( | |
id Int PRIMARY KEY , | |
title varchar(255), | |
author_id Int REFERENCES Author(id) | |
); | |
Create TABLE Bookshelf( | |
id Int PRIMARY KEY , | |
name varchar(255) | |
); | |
Create TABLE bookshelf_stories_story ( | |
story_id Int REFERENCES Story (id), | |
bookshelf_id Int REFERENCES Bookshelf (id), | |
); | |
REQUESTED NEW | |
DELETE | |
--Array | |
--Array | |
--Do something | |
UPDATE Story SET(id,title)= (?,?) WHERE id = ?; | |
INSERT INTO Story(id,title) VALUES(?,?) | |
root@testperl6:~/piko/qdorm# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment