diff --git a/core-concepts/modules/ROOT/pages/typeql/index.adoc b/core-concepts/modules/ROOT/pages/typeql/index.adoc index 1e3399193..e8e6218b0 100644 --- a/core-concepts/modules/ROOT/pages/typeql/index.adoc +++ b/core-concepts/modules/ROOT/pages/typeql/index.adoc @@ -67,10 +67,4 @@ A deeper look at invalid patterns involving disjoint variable reuse **** Short definitions of terms used throughout the guide, with links to the section which introduces them. **** - -.xref:{page-version}@core-concepts::typeql/sql-vs-typeql.adoc[] -[.clickable] -**** -A guide of relational constructs in SQL compared to similar concepts in TypeQL. -**** -- diff --git a/core-concepts/modules/ROOT/partials/nav.adoc b/core-concepts/modules/ROOT/partials/nav.adoc index 2a0e60655..66e1a8cd8 100644 --- a/core-concepts/modules/ROOT/partials/nav.adoc +++ b/core-concepts/modules/ROOT/partials/nav.adoc @@ -22,7 +22,6 @@ ** xref:{page-version}@core-concepts::typeql/invalid-patterns.adoc[] // ** xref:{page-version}@core-concepts::typeql/best-practices.adoc[] ** xref:{page-version}@core-concepts::typeql/glossary.adoc[] -** xref:{page-version}@core-concepts::typeql/sql-vs-typeql.adoc[] * xref:{page-version}@core-concepts::drivers/index.adoc[] diff --git a/tutorials/antora.yml b/guides/antora.yml similarity index 58% rename from tutorials/antora.yml rename to guides/antora.yml index efb085986..1d8b6d7e5 100644 --- a/tutorials/antora.yml +++ b/guides/antora.yml @@ -1,5 +1,5 @@ -name: tutorials -title: Tutorials +name: guides +title: Guides version: '3.x' nav: - modules/ROOT/nav.adoc diff --git a/guides/modules/ROOT/attachments/bookstore-data.tql b/guides/modules/ROOT/attachments/bookstore-data.tql new file mode 100644 index 000000000..59eccb7ae --- /dev/null +++ b/guides/modules/ROOT/attachments/bookstore-data.tql @@ -0,0 +1,545 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# country +insert $country isa country, has name "United States";end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "California"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "Texas"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "New York"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "New Jersey"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "Washington"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "Massachusetts"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "New Mexico"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "United States"; insert $state isa state, has name "Missouri"; (location: $country, located: $state) isa locating;end; +# city +match $state isa state, has name "California"; insert $city isa city, has name "Sacramento"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "California"; insert $city isa city, has name "Los Angeles"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "California"; insert $city isa city, has name "San Francisco"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "California"; insert $city isa city, has name "Sevastopol"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Texas"; insert $city isa city, has name "Austin"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New York"; insert $city isa city, has name "Albany"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New York"; insert $city isa city, has name "New York City"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New Jersey"; insert $city isa city, has name "Trenton"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New Jersey"; insert $city isa city, has name "Newark"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Washington"; insert $city isa city, has name "Seattle"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Massachusetts"; insert $city isa city, has name "Boston"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New Mexico"; insert $city isa city, has name "Santa Fe"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "New Mexico"; insert $city isa city, has name "Albuquerque"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Missouri"; insert $city isa city, has name "Kansas City"; (location: $state, located: $city) isa locating;end; +# country +insert $country isa country, has name "United Kingdom";end; +# city +match $country isa country, has name "United Kingdom"; insert $city isa city, has name "London"; (location: $country, located: $city) isa locating;end; +# city +match $country isa country, has name "United Kingdom"; insert $city isa city, has name "Bristol"; (location: $country, located: $city) isa locating;end; +# city +match $country isa country, has name "United Kingdom"; insert $city isa city, has name "Liverpool"; (location: $country, located: $city) isa locating;end; +# country +insert $country isa country, has name "Canada";end; +# state +match $country isa country, has name "Canada"; insert $state isa state, has name "Ontario"; (location: $country, located: $state) isa locating;end; +# state +match $country isa country, has name "Canada"; insert $state isa state, has name "Quebec"; (location: $country, located: $state) isa locating;end; +# city +match $state isa state, has name "Ontario"; insert $city isa city, has name "Toronto"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Quebec"; insert $city isa city, has name "Quebec City"; (location: $state, located: $city) isa locating;end; +# city +match $state isa state, has name "Quebec"; insert $city isa city, has name "Montreal"; (location: $state, located: $city) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780195153446", has title "Classical Mythology", has page-count 820, has price 34.98, has genre "nonfiction", has genre "history", has isbn-10 "0195153448", has stock 12;end; +put $contributor isa contributor, has name "Morford, Mark P. O."; match $book isa paperback, has isbn-13 "9780195153446"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Lenardon, Robert J."; match $book isa paperback, has isbn-13 "9780195153446"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Oxford University Press"; match $book isa paperback, has isbn-13 "9780195153446"; $city isa city, has name "New York City"; insert $publication isa publication, has year 2002; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa hardback, has isbn-13 "9780679425601", has title "Under the Black Flag: The Romance and the Reality of Life Among the Pirates", has page-count 296, has price 34.73, has genre "nonfiction", has genre "history", has isbn-10 "0679425608", has stock 13;end; +put $contributor isa contributor, has name "Cordingly, David"; match $book isa hardback, has isbn-13 "9780679425601"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Random House"; match $book isa hardback, has isbn-13 "9780679425601"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1996; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780393045215", has title "The Mummies of Urumchi", has page-count 240, has price 21.60, has genre "nonfiction", has genre "history", has isbn-10 "0393045218", has stock 1;end; +put $contributor isa contributor, has name "Barber, Elizabeth Wayland"; match $book isa paperback, has isbn-13 "9780393045215"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "W.W. Norton & Company"; match $book isa paperback, has isbn-13 "9780393045215"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1999; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9798691153570", has title "Business Secrets of The Pharoahs", has page-count 260, has price 11.99, has genre "nonfiction", has genre "business", has stock 8;end; +put $contributor isa contributor, has name "Crorigan, Mark"; match $book isa paperback, has isbn-13 "9798691153570"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "British London Publishing"; match $book isa paperback, has isbn-13 "9798691153570"; $city isa city, has name "London"; insert $publication isa publication, has year 2020; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780446310789", has title "To Kill a Mockingbird", has page-count 281, has price 21.64, has genre "fiction", has genre "historical fiction", has isbn-10 "0446310786", has stock 16;end; +put $contributor isa contributor, has name "Harper Lee"; match $book isa paperback, has isbn-13 "9780446310789"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Grand Central Publishing"; match $book isa paperback, has isbn-13 "9780446310789"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1988; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780553212150", has title "Pride and Prejudice", has page-count 295, has price 17.99, has genre "fiction", has genre "historical fiction", has isbn-10 "055321215X", has stock 15;end; +put $contributor isa contributor, has name "Austen, Jane"; match $book isa paperback, has isbn-13 "9780553212150"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Bantam Classics"; match $book isa paperback, has isbn-13 "9780553212150"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1983; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9783319398778", has title "Physical Principles of Electron Microscopy: An Introduction to TEM, SEM, and AEM", has page-count 196, has price 19.50, has genre "nonfiction", has genre "technology";end; +put $contributor isa contributor, has name "Egerton, R.F."; match $book isa ebook, has isbn-13 "9783319398778"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Springer"; match $book isa ebook, has isbn-13 "9783319398778"; $city isa city, has name "London"; insert $publication isa publication, has year 2016; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa hardback, has isbn-13 "9780387881355", has title "Electron Backscatter Diffraction in Materials Science", has page-count 425, has price 230.37, has genre "nonfiction", has genre "technology", has isbn-10 "0387881352", has stock 9;end; +put $contributor isa contributor, has name "Schwartz, Adam J."; match $book isa hardback, has isbn-13 "9780387881355"; insert (work: $book, editor: $contributor) isa editing;end; +put $contributor isa contributor, has name "Kumar, Mukul"; match $book isa hardback, has isbn-13 "9780387881355"; insert (work: $book, editor: $contributor) isa editing;end; +put $contributor isa contributor, has name "Adams, Brent L."; match $book isa hardback, has isbn-13 "9780387881355"; insert (work: $book, editor: $contributor) isa editing;end; +put $contributor isa contributor, has name "Field, David P."; match $book isa hardback, has isbn-13 "9780387881355"; insert (work: $book, editor: $contributor) isa editing;end; +put $publisher isa publisher, has name "Springer"; match $book isa hardback, has isbn-13 "9780387881355"; $city isa city, has name "New York City"; insert $publication isa publication, has year 2009; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9781489962287", has title "Interpretation of Electron Diffraction Patterns", has page-count 199, has price 47.17, has genre "nonfiction", has genre "technology", has isbn-10 "148996228X", has stock 15;end; +put $contributor isa contributor, has name "Andrews, Kenneth William"; match $book isa paperback, has isbn-13 "9781489962287"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Dyson, David John"; match $book isa paperback, has isbn-13 "9781489962287"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Keown, Samuel Robert"; match $book isa paperback, has isbn-13 "9781489962287"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Springer"; match $book isa paperback, has isbn-13 "9781489962287"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1967; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780500026557", has title "Hokusai's Fuji", has page-count 416, has price 24.47, has genre "nonfiction", has genre "art", has isbn-10 "0500026556", has stock 11;end; +put $contributor isa contributor, has name "Wada, Kyoko"; match $book isa paperback, has isbn-13 "9780500026557"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Katsushika, Hokusai"; match $book isa paperback, has isbn-13 "9780500026557"; insert (work: $book, illustrator: $contributor) isa illustrating;end; +put $publisher isa publisher, has name "Thames & Hudson"; match $book isa paperback, has isbn-13 "9780500026557"; $city isa city, has name "London"; insert $publication isa publication, has year 2024; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780500291221", has title "Great Discoveries in Medicine", has page-count 352, has price 12.05, has genre "nonfiction", has genre "history", has isbn-10 "0500291225", has stock 18;end; +put $contributor isa contributor, has name "Bynum, William"; match $book isa paperback, has isbn-13 "9780500291221"; insert (work: $book, editor: $contributor) isa editing;end; +put $contributor isa contributor, has name "Bynum, Helen"; match $book isa paperback, has isbn-13 "9780500291221"; insert (work: $book, editor: $contributor) isa editing;end; +put $publisher isa publisher, has name "Thames & Hudson"; match $book isa paperback, has isbn-13 "9780500291221"; $city isa city, has name "London"; insert $publication isa publication, has year 2023; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa hardback, has isbn-13 "9780740748479", has title "The Complete Calvin and Hobbes", has page-count 1451, has price 128.71, has genre "fiction", has genre "comics", has isbn-10 "0740748475", has stock 6;end; +put $contributor isa contributor, has name "Watterson, Bill"; match $book isa hardback, has isbn-13 "9780740748479"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Watterson, Bill"; match $book isa hardback, has isbn-13 "9780740748479"; insert (work: $book, illustrator: $contributor) isa illustrating;end; +put $publisher isa publisher, has name "Andrews McMeel Publishing"; match $book isa hardback, has isbn-13 "9780740748479"; $city isa city, has name "Kansas City"; insert $publication isa publication, has year 2005; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9780375801679", has title "The Iron Giant", has page-count 79, has price 33.97, has genre "fiction", has genre "children's fiction", has isbn-10 "0375801677";end; +put $contributor isa contributor, has name "Hughes, Ted"; match $book isa ebook, has isbn-13 "9780375801679"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Davidson, Andrew"; match $book isa ebook, has isbn-13 "9780375801679"; insert (work: $book, illustrator: $contributor) isa illustrating;end; +put $publisher isa publisher, has name "Knopf Books for Young Readers"; match $book isa ebook, has isbn-13 "9780375801679"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1999; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9781859840665", has title "The Motorcycle Diaries: A Journey Around South America", has page-count 160, has price 14.52, has genre "nonfiction", has genre "biography", has isbn-10 "1859840663", has stock 4;end; +put $contributor isa contributor, has name "Guevara, Ernesto"; match $book isa paperback, has isbn-13 "9781859840665"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Wright, Ann"; match $book isa paperback, has isbn-13 "9781859840665"; insert (work: $book, contributor: $contributor) isa contribution;end; +put $publisher isa publisher, has name "Verso"; match $book isa paperback, has isbn-13 "9781859840665"; $city isa city, has name "London"; insert $publication isa publication, has year 1996; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780671461492", has title "The Hitchhiker's Guide to the Galaxy", has page-count 215, has price 91.47, has genre "fiction", has genre "science fiction", has isbn-10 "0671461494", has stock 9;end; +put $contributor isa contributor, has name "Adams, Douglas"; match $book isa paperback, has isbn-13 "9780671461492"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Pocket"; match $book isa paperback, has isbn-13 "9780671461492"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1982; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780060929794", has title "One Hundred Years of Solitude", has page-count 458, has price 6.12, has genre "fiction", has genre "historical fiction", has isbn-10 "0060929790", has stock 4;end; +put $contributor isa contributor, has name "Garcia Marquez, Gabriel"; match $book isa paperback, has isbn-13 "9780060929794"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Perennial"; match $book isa paperback, has isbn-13 "9780060929794"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1998; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa paperback, has isbn-13 "9780451162076", has title "Pet Sematary", has page-count 374, has price 93.22, has genre "fiction", has genre "horror", has isbn-10 "0451162072", has stock 1;end; +put $contributor isa contributor, has name "King, Stephen"; match $book isa paperback, has isbn-13 "9780451162076"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Signet"; match $book isa paperback, has isbn-13 "9780451162076"; $city isa city, has name "New York City"; insert $publication isa publication, has year 1984; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9781098108274", has title "Fundamentals of Data Engineering", has page-count 450, has price 47.99, has genre "nonfiction", has genre "technology", has genre "children's fiction", has isbn-10 "1098108272";end; +put $contributor isa contributor, has name "Reis, Joe"; match $book isa ebook, has isbn-13 "9781098108274"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Housley, Matt"; match $book isa ebook, has isbn-13 "9781098108274"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "O'Reilly Media"; match $book isa ebook, has isbn-13 "9781098108274"; $city isa city, has name "Sevastopol"; insert $publication isa publication, has year 2022; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9780393634563", has title "The Odyssey", has page-count 656, has price 13.99, has genre "fiction", has genre "classics", has isbn-10 "0393634566";end; +put $contributor isa contributor, has name "Homer"; match $book isa ebook, has isbn-13 "9780393634563"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "Wilson, Emily"; match $book isa ebook, has isbn-13 "9780393634563"; insert (work: $book, contributor: $contributor) isa contribution;end; +put $publisher isa publisher, has name "W.W. Norton & Company"; match $book isa ebook, has isbn-13 "9780393634563"; $city isa city, has name "New York City"; insert $publication isa publication, has year 2017; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9780575104419", has title "Dune", has page-count 624, has price 5.49, has genre "fiction", has genre "science fiction", has isbn-10 "0575104414";end; +put $contributor isa contributor, has name "Herbert, Frank"; match $book isa ebook, has isbn-13 "9780575104419"; insert (work: $book, author: $contributor) isa authoring;end; +put $publisher isa publisher, has name "Hachette Book Group"; match $book isa ebook, has isbn-13 "9780575104419"; $city isa city, has name "New York City"; insert $publication isa publication, has year 2010; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# book +insert $book isa ebook, has isbn-13 "9780008627843", has title "The Hobbit", has page-count 310, has price 16.99, has genre "fiction", has genre "fantasy", has isbn-10 "0008627843";end; +put $contributor isa contributor, has name "J.R.R. Tolkien"; match $book isa ebook, has isbn-13 "9780008627843"; insert (work: $book, author: $contributor) isa authoring;end; +put $contributor isa contributor, has name "J.R.R. Tolkien"; match $book isa ebook, has isbn-13 "9780008627843"; insert (work: $book, illustrator: $contributor) isa illustrating;end; +put $publisher isa publisher, has name "Harper Collins"; match $book isa ebook, has isbn-13 "9780008627843"; $city isa city, has name "New York City"; insert $publication isa publication, has year 2023; (published: $book, publisher: $publisher, publication: $publication) isa publishing; (location: $city, located: $publication) isa locating;end; + +# user +match $city isa city, has name "San Francisco"; insert $user isa user, has id "u0001", has name "Kevin Morrison", has birth-date 1995-10-29, has total-spending 263.08, has loyalty-tier 1; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Austin"; insert $user isa user, has id "u0002", has name "Cameron Osborne", has birth-date 1954-11-11, has total-spending 22.51, has loyalty-tier 0; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Newark"; insert $user isa user, has id "u0003", has name "Keyla Pineda", has birth-date 1977-06-20, has total-spending 1026.65, has loyalty-tier 3; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Seattle"; insert $user isa user, has id "u0004", has name "Lorenzo Nixon", has birth-date 1985-08-15, has total-spending 3811.99, has loyalty-tier 5; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Boston"; insert $user isa user, has id "u0005", has name "Xavier Martinez", has birth-date 1985-01-03, has total-spending 74.18, has loyalty-tier 0; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Santa Fe"; insert $user isa user, has id "u0006", has name "Giovanni Beard", has birth-date 1992-11-01, has total-spending 1894.24, has loyalty-tier 4; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Toronto"; insert $user isa user, has id "u0007", has name "Skyler Townsend", has birth-date 1971-04-24, has total-spending 943.87, has loyalty-tier 3; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Bristol"; insert $user isa user, has id "u0008", has name "Alia Hartman", has birth-date 1962-10-08, has total-spending 766.51, has loyalty-tier 2; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Montreal"; insert $user isa user, has id "u0009", has name "Isaac Winters", has birth-date 1984-08-03, has total-spending 442.90, has loyalty-tier 2; (location: $city, located: $user) isa locating;end; +# user +match $city isa city, has name "Liverpool"; insert $user isa user, has id "u0010", has name "Madison Everett", has birth-date 1981-02-10, has total-spending 1854.86, has loyalty-tier 5; (location: $city, located: $user) isa locating;end; + +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "San Francisco"; put $address isa address, has street "14 South Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0001"; $courier isa courier, has name "UPS"; $city isa city, has name "San Francisco"; insert $order isa order, has id "o0001", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-08-03T19:51:24.324; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0001"; $book isa book, has isbn-13 "9780393634563"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +match $order isa order, has id "o0001"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "San Francisco"; put $address isa address, has street "14 South Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0001"; $courier isa courier, has name "FedEx"; $city isa city, has name "San Francisco"; insert $order isa order, has id "o0002", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2021-04-27T05:02:39.672; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0002"; $book isa book, has isbn-13 "9780575104419"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "San Francisco"; put $address isa address, has street "14 South Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0001"; $courier isa courier, has name "UPS"; $city isa city, has name "San Francisco"; insert $order isa order, has id "o0003", has status "returned"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-11-25T04:56:09.945; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0003"; $book isa book, has isbn-13 "9781489962287"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Austin"; put $address isa address, has street "55 Park Road"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0002"; $courier isa courier, has name "DHL"; $city isa city, has name "Austin"; insert $order isa order, has id "o0004", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-12-17T08:33:51.241; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0004"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Austin"; put $address isa address, has street "55 Park Road"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0002"; $courier isa courier, has name "FedEx"; $city isa city, has name "Austin"; insert $order isa order, has id "o0005", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-08-16T21:41:44.938; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0005"; $book isa book, has isbn-13 "9783319398778"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Austin"; put $address isa address, has street "55 Park Road"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0002"; $courier isa courier, has name "FedEx"; $city isa city, has name "Austin"; insert $order isa order, has id "o0006", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-08-19T20:21:54.194; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0006"; $book isa book, has isbn-13 "9780740748479"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Austin"; put $address isa address, has street "55 Park Road"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0002"; $courier isa courier, has name "DHL"; $city isa city, has name "Austin"; insert $order isa order, has id "o0007", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-02-23T07:23:50.174; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0007"; $book isa book, has isbn-13 "9780387881355"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Newark"; put $address isa address, has street "23 Grove Road"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0003"; $courier isa courier, has name "UPS"; $city isa city, has name "Newark"; insert $order isa order, has id "o0008", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2021-12-08T01:52:36.649; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0008"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0008"; $book isa book, has isbn-13 "9781859840665"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Seattle"; put $address isa address, has street "9735 Queensway"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0004"; $courier isa courier, has name "UPS"; $city isa city, has name "Seattle"; insert $order isa order, has id "o0009", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2021-10-27T18:07:25.093; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0009"; $book isa book, has isbn-13 "9780393634563"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0009"; $book isa book, has isbn-13 "9780008627843"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0009"; $book isa book, has isbn-13 "9780393045215"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Seattle"; put $address isa address, has street "9735 Queensway"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0004"; $courier isa courier, has name "UPS"; $city isa city, has name "Seattle"; insert $order isa order, has id "o0010", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-04-06T22:07:30.215; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0010"; $book isa book, has isbn-13 "9780740748479"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Boston"; put $address isa address, has street "64 Fremont Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0005"; $courier isa courier, has name "DHL"; $city isa city, has name "Boston"; insert $order isa order, has id "o0011", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-10-04T08:04:14.073; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0011"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Santa Fe"; put $address isa address, has street "9227 Lincoln Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0006"; $courier isa courier, has name "FedEx"; $city isa city, has name "Santa Fe"; insert $order isa order, has id "o0012", has status "delivered"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2021-01-17T14:02:38.103; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0012"; $book isa book, has isbn-13 "9780500026557"; insert $line isa order-line, links (order: $order, item: $book), has quantity 3;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Santa Fe"; put $address isa address, has street "9227 Lincoln Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0006"; $courier isa courier, has name "FedEx"; $city isa city, has name "Santa Fe"; insert $order isa order, has id "o0013", has status "delivered"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-10-06T22:43:13.989; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0013"; $book isa book, has isbn-13 "9780375801679"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0013"; $book isa book, has isbn-13 "9783319398778"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Santa Fe"; put $address isa address, has street "9227 Lincoln Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0006"; $courier isa courier, has name "FedEx"; $city isa city, has name "Santa Fe"; insert $order isa order, has id "o0014", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-02-20T14:42:11.013; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0014"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +match $order isa order, has id "o0014"; $book isa book, has isbn-13 "9780553212150"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Toronto"; put $address isa address, has street "464 Pilgrim Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "DHL"; $city isa city, has name "Toronto"; insert $order isa order, has id "o0015", has status "returned"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-11-12T12:53:42.256; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0015"; $book isa book, has isbn-13 "9780060929794"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Toronto"; put $address isa address, has street "464 Pilgrim Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "FedEx"; $city isa city, has name "Toronto"; insert $order isa order, has id "o0016", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-06-24T01:34:17.138; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0016"; $book isa book, has isbn-13 "9780446310789"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0016"; $book isa book, has isbn-13 "9780393634563"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Bristol"; put $address isa address, has street "75 Fairway Court"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0008"; $courier isa courier, has name "DHL"; $city isa city, has name "Bristol"; insert $order isa order, has id "o0017", has status "delivered"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-11-12T18:57:40.874; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0017"; $book isa book, has isbn-13 "9780387881355"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0017"; $book isa book, has isbn-13 "9780060929794"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Bristol"; put $address isa address, has street "75 Fairway Court"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0008"; $courier isa courier, has name "DHL"; $city isa city, has name "Bristol"; insert $order isa order, has id "o0018", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-07-24T13:53:41.082; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0018"; $book isa book, has isbn-13 "9780008627843"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Montreal"; put $address isa address, has street "86 East Drive"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0009"; $courier isa courier, has name "UPS"; $city isa city, has name "Montreal"; insert $order isa order, has id "o0019", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-03-08T07:40:28.387; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0019"; $book isa book, has isbn-13 "9780195153446"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Montreal"; put $address isa address, has street "86 East Drive"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0009"; $courier isa courier, has name "UPS"; $city isa city, has name "Montreal"; insert $order isa order, has id "o0020", has status "returned"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-12-19T13:49:42.726; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0020"; $book isa book, has isbn-13 "9780575104419"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Montreal"; put $address isa address, has street "86 East Drive"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0009"; $courier isa courier, has name "FedEx"; $city isa city, has name "Montreal"; insert $order isa order, has id "o0021", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-05-23T05:28:33.906; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0021"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Liverpool"; put $address isa address, has street "75 Selby Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0010"; $courier isa courier, has name "UPS"; $city isa city, has name "Liverpool"; insert $order isa order, has id "o0022", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-08-11T09:53:29.051; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0022"; $book isa book, has isbn-13 "9780060929794"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0022"; $book isa book, has isbn-13 "9780393634563"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Liverpool"; put $address isa address, has street "75 Selby Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0010"; $courier isa courier, has name "DHL"; $city isa city, has name "Liverpool"; insert $order isa order, has id "o0023", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-12-05T00:25:43.427; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0023"; $book isa book, has isbn-13 "9781859840665"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0023"; $book isa book, has isbn-13 "9783319398778"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Liverpool"; put $address isa address, has street "75 Selby Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0010"; $courier isa courier, has name "UPS"; $city isa city, has name "Liverpool"; insert $order isa order, has id "o0024", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-12-25T00:52:43.541; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0024"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Sacramento"; put $address isa address, has street "786 Lake View Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0005"; $courier isa courier, has name "UPS"; $city isa city, has name "Sacramento"; insert $order isa order, has id "o0025", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-10-21T06:55:19.286; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0025"; $book isa book, has isbn-13 "9780008627843"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Sacramento"; put $address isa address, has street "786 Lake View Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0005"; $courier isa courier, has name "FedEx"; $city isa city, has name "Sacramento"; insert $order isa order, has id "o0026", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-11-03T00:17:58.463; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0026"; $book isa book, has isbn-13 "9780553212150"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Sacramento"; put $address isa address, has street "786 Lake View Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0005"; $courier isa courier, has name "UPS"; $city isa city, has name "Sacramento"; insert $order isa order, has id "o0027", has status "delivered"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-02-28T04:17:54.019; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0027"; $book isa book, has isbn-13 "9798691153570"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "New York City"; put $address isa address, has street "8503 Second Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0003"; $courier isa courier, has name "UPS"; $city isa city, has name "New York City"; insert $order isa order, has id "o0028", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-09-11T11:36:58.869; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0028"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "New York City"; put $address isa address, has street "8503 Second Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0003"; $courier isa courier, has name "DHL"; $city isa city, has name "New York City"; insert $order isa order, has id "o0029", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-12-21T14:40:27.381; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0029"; $book isa book, has isbn-13 "9780679425601"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Kansas City"; put $address isa address, has street "826 Vermont Avenue"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0004"; $courier isa courier, has name "UPS"; $city isa city, has name "Kansas City"; insert $order isa order, has id "o0030", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-10-10T00:08:09.277; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0030"; $book isa book, has isbn-13 "9780393634563"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Los Angeles"; put $address isa address, has street "984 Williams Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0001"; $courier isa courier, has name "FedEx"; $city isa city, has name "Los Angeles"; insert $order isa order, has id "o0031", has status "delivered"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-06-25T19:02:02.276; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0031"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Los Angeles"; put $address isa address, has street "984 Williams Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0001"; $courier isa courier, has name "FedEx"; $city isa city, has name "Los Angeles"; insert $order isa order, has id "o0032", has status "canceled"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2022-07-18T04:18:07.489; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0032"; $book isa book, has isbn-13 "9780553212150"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0032"; $book isa book, has isbn-13 "9780446310789"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Quebec City"; put $address isa address, has street "20 Ridge Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "FedEx"; $city isa city, has name "Quebec City"; insert $order isa order, has id "o0033", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2021-09-24T02:19:25.855; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0033"; $book isa book, has isbn-13 "9780387881355"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "UPS"; end; +match $city isa city, has name "Quebec City"; put $address isa address, has street "20 Ridge Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "UPS"; $city isa city, has name "Quebec City"; insert $order isa order, has id "o0034", has status "returned"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-09-30T15:30:21.861; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0034"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0034"; $book isa book, has isbn-13 "9780500026557"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Quebec City"; put $address isa address, has street "20 Ridge Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "FedEx"; $city isa city, has name "Quebec City"; insert $order isa order, has id "o0035", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-12-16T13:02:19.343; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0035"; $book isa book, has isbn-13 "9780500291221"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "DHL"; end; +match $city isa city, has name "Quebec City"; put $address isa address, has street "20 Ridge Lane"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0007"; $courier isa courier, has name "DHL"; $city isa city, has name "Quebec City"; insert $order isa order, has id "o0036", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2023-11-03T02:51:05.202; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0036"; $book isa book, has isbn-13 "9780446310789"; insert $line isa order-line, links (order: $order, item: $book), has quantity 2;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Albany"; put $address isa address, has street "112 Church Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0003"; $courier isa courier, has name "FedEx"; $city isa city, has name "Albany"; insert $order isa order, has id "o0037", has status "paid"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-02-13T17:33:18.459; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0037"; $book isa book, has isbn-13 "9780387881355"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +# order +put $courier isa courier, has name "FedEx"; end; +match $city isa city, has name "Albany"; put $address isa address, has street "112 Church Street"; (location: $city, located: $address) isa locating;match $user isa user, has id "u0003"; $courier isa courier, has name "FedEx"; $city isa city, has name "Albany"; insert $order isa order, has id "o0038", has status "dispatched"; $execution isa action-execution, links (action: $order, executor: $user), has timestamp 2020-06-08T08:37:49.170; (delivered: $order, deliverer: $courier, destination: $address) isa delivery;end; +match $order isa order, has id "o0038"; $book isa book, has isbn-13 "9780060929794"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; +match $order isa order, has id "o0038"; $book isa book, has isbn-13 "9780575104419"; insert $line isa order-line, links (order: $order, item: $book), has quantity 1;end; + +# review +match $book isa book, has isbn-13 "9780195153446"; $user isa user, has id "u0009"; insert $review isa review, has id "r0001", has score 4; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-04-12T03:04:52.884;end; +# review +match $book isa book, has isbn-13 "9783319398778"; $user isa user, has id "u0001"; insert $review isa review, has id "r0002", has score 5; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-11-07T03:31:25.262;end; +# review +match $book isa book, has isbn-13 "9780740748479"; $user isa user, has id "u0009"; insert $review isa review, has id "r0003", has score 5; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-10-05T03:12:29.387;end; +# review +match $book isa book, has isbn-13 "9781859840665"; $user isa user, has id "u0009"; insert $review isa review, has id "r0004", has score 5; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-02-20T15:09:36.415;end; +# review +match $book isa book, has isbn-13 "9783319398778"; $user isa user, has id "u0009"; insert $review isa review, has id "r0005", has score 6; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-11-30T10:53:31.510;end; +# review +match $book isa book, has isbn-13 "9780500291221"; $user isa user, has id "u0001"; insert $review isa review, has id "r0006", has score 6; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-01-11T22:47:57.325;end; +# review +match $book isa book, has isbn-13 "9780500026557"; $user isa user, has id "u0008"; insert $review isa review, has id "r0007", has score 6; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-05-20T04:53:24.596;end; +# review +match $book isa book, has isbn-13 "9780679425601"; $user isa user, has id "u0005"; insert $review isa review, has id "r0008", has score 6; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-02-17T01:04:14.133;end; +# review +match $book isa book, has isbn-13 "9780671461492"; $user isa user, has id "u0006"; insert $review isa review, has id "r0009", has score 6; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-08-11T05:51:09.889;end; +# review +match $book isa book, has isbn-13 "9781098108274"; $user isa user, has id "u0010"; insert $review isa review, has id "r0010", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-09-17T01:36:05.694;end; +# review +match $book isa book, has isbn-13 "9780008627843"; $user isa user, has id "u0007"; insert $review isa review, has id "r0011", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-12-14T06:18:34.922;end; +# review +match $book isa book, has isbn-13 "9780195153446"; $user isa user, has id "u0001"; insert $review isa review, has id "r0012", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-07-20T18:14:54.885;end; +# review +match $book isa book, has isbn-13 "9780060929794"; $user isa user, has id "u0005"; insert $review isa review, has id "r0013", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-05-17T18:16:21.067;end; +# review +match $book isa book, has isbn-13 "9780446310789"; $user isa user, has id "u0004"; insert $review isa review, has id "r0014", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-07-13T12:03:10.656;end; +# review +match $book isa book, has isbn-13 "9781859840665"; $user isa user, has id "u0003"; insert $review isa review, has id "r0015", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-12-27T10:03:02.492;end; +# review +match $book isa book, has isbn-13 "9780740748479"; $user isa user, has id "u0007"; insert $review isa review, has id "r0016", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-10-23T02:43:44.155;end; +# review +match $book isa book, has isbn-13 "9780060929794"; $user isa user, has id "u0003"; insert $review isa review, has id "r0017", has score 7; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-10-15T12:29:03.103;end; +# review +match $book isa book, has isbn-13 "9798691153570"; $user isa user, has id "u0009"; insert $review isa review, has id "r0018", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-01-20T19:08:40.331;end; +# review +match $book isa book, has isbn-13 "9780008627843"; $user isa user, has id "u0008"; insert $review isa review, has id "r0019", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-04-13T15:07:56.061;end; +# review +match $book isa book, has isbn-13 "9780446310789"; $user isa user, has id "u0007"; insert $review isa review, has id "r0020", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-11-04T21:45:39.303;end; +# review +match $book isa book, has isbn-13 "9783319398778"; $user isa user, has id "u0001"; insert $review isa review, has id "r0021", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-12-28T21:51:07.531;end; +# review +match $book isa book, has isbn-13 "9780393045215"; $user isa user, has id "u0001"; insert $review isa review, has id "r0022", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-08-12T06:29:22.808;end; +# review +match $book isa book, has isbn-13 "9780575104419"; $user isa user, has id "u0004"; insert $review isa review, has id "r0023", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-08-09T00:33:42.582;end; +# review +match $book isa book, has isbn-13 "9781098108274"; $user isa user, has id "u0007"; insert $review isa review, has id "r0024", has score 8; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-02-25T20:49:32.715;end; +# review +match $book isa book, has isbn-13 "9780393045215"; $user isa user, has id "u0002"; insert $review isa review, has id "r0025", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-02-05T13:57:36.432;end; +# review +match $book isa book, has isbn-13 "9780195153446"; $user isa user, has id "u0008"; insert $review isa review, has id "r0026", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-02-04T13:49:09.751;end; +# review +match $book isa book, has isbn-13 "9780500291221"; $user isa user, has id "u0005"; insert $review isa review, has id "r0027", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-11-14T00:31:58.884;end; +# review +match $book isa book, has isbn-13 "9780740748479"; $user isa user, has id "u0006"; insert $review isa review, has id "r0028", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2020-06-03T03:22:44.030;end; +# review +match $book isa book, has isbn-13 "9780008627843"; $user isa user, has id "u0003"; insert $review isa review, has id "r0029", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-01-27T07:52:23.072;end; +# review +match $book isa book, has isbn-13 "9798691153570"; $user isa user, has id "u0001"; insert $review isa review, has id "r0030", has score 9; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2021-01-07T21:43:46.960;end; +# review +match $book isa book, has isbn-13 "9780446310789"; $user isa user, has id "u0003"; insert $review isa review, has id "r0031", has score 10; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-06-23T00:59:38.238;end; +# review +match $book isa book, has isbn-13 "9780195153446"; $user isa user, has id "u0004"; insert $review isa review, has id "r0032", has score 10; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2023-02-16T11:45:16.133;end; +# review +match $book isa book, has isbn-13 "9780393634563"; $user isa user, has id "u0006"; insert $review isa review, has id "r0033", has score 10; (review: $review, rated: $book) isa rating; $execution isa action-execution, links (action: $review, executor: $user), has timestamp 2022-06-16T09:18:59.899;end; + +# login +match $user isa user, has id "u0003"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-02-18T18:19:10.385;end; +# login +match $user isa user, has id "u0005"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-06-17T07:15:48.188;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-11-02T04:38:01.403;end; +# login +match $user isa user, has id "u0003"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-03-14T09:35:26.758;end; +# login +match $user isa user, has id "u0006"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-05-21T11:05:15.455;end; +# login +match $user isa user, has id "u0006"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-07-14T00:26:46.922;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-06-10T15:05:11.815;end; +# login +match $user isa user, has id "u0008"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-09-20T22:09:50.719;end; +# login +match $user isa user, has id "u0009"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-07-14T05:15:29.348;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-08-21T20:05:30.773;end; +# login +match $user isa user, has id "u0005"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-12-15T19:29:00.223;end; +# login +match $user isa user, has id "u0008"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-09-20T04:27:45.769;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-04-18T12:17:40.022;end; +# login +match $user isa user, has id "u0007"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-01-09T12:33:56.595;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-12-09T11:18:55.773;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-01-03T08:19:34.348;end; +# login +match $user isa user, has id "u0009"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-03-03T13:55:18.289;end; +# login +match $user isa user, has id "u0005"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-09-04T13:40:34.413;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-06-19T20:08:10.126;end; +# login +match $user isa user, has id "u0006"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-10-15T04:35:42.306;end; +# login +match $user isa user, has id "u0009"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-12-14T06:30:31.711;end; +# login +match $user isa user, has id "u0008"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-11-02T14:19:09.763;end; +# login +match $user isa user, has id "u0009"; insert $login isa login, has success false; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-01-12T15:25:56.010;end; +# login +match $user isa user, has id "u0001"; insert $login isa login, has success false; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-11-24T21:25:00.369;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-05-28T20:44:18.744;end; +# login +match $user isa user, has id "u0007"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-04-04T13:29:45.338;end; +# login +match $user isa user, has id "u0003"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-07-21T21:27:09.458;end; +# login +match $user isa user, has id "u0007"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-03-07T05:28:22.808;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-07-24T07:50:12.449;end; +# login +match $user isa user, has id "u0003"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-07-02T07:40:05.891;end; +# login +match $user isa user, has id "u0005"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-12-21T21:11:14.625;end; +# login +match $user isa user, has id "u0006"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-12-28T16:48:18.789;end; +# login +match $user isa user, has id "u0009"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-01-21T22:33:42.979;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2023-10-15T15:16:45.487;end; +# login +match $user isa user, has id "u0005"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-01-02T01:10:22.003;end; +# login +match $user isa user, has id "u0010"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2020-03-03T13:43:14.993;end; +# login +match $user isa user, has id "u0002"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2021-08-07T10:38:06.620;end; +# login +match $user isa user, has id "u0001"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-09-15T10:16:01.534;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-02-07T16:22:12.857;end; +# login +match $user isa user, has id "u0004"; insert $login isa login, has success true; $execution isa action-execution, links (action: $login, executor: $user), has timestamp 2022-05-17T12:16:30.352;end; + +# promotion +insert $promotion isa promotion, has code "HOL23", has name "Holiday Sale 2023", has start-timestamp 2023-12-01T00:00:00, has end-timestamp 2023-12-31T23:59:59;end; +match $book isa book, has isbn-13 "9780575104419"; $promotion isa promotion, has name "Holiday Sale 2023"; insert $inclusion isa promotion-inclusion, links (promotion: $promotion, item: $book), has discount 0.25;end; +match $book isa book, has isbn-13 "9780060929794"; $promotion isa promotion, has name "Holiday Sale 2023"; insert $inclusion isa promotion-inclusion, links (promotion: $promotion, item: $book), has discount 0.25;end; +match $book isa book, has isbn-13 "9780375801679"; $promotion isa promotion, has name "Holiday Sale 2023"; insert $inclusion isa promotion-inclusion, links (promotion: $promotion, item: $book), has discount 0.25;end; +match $book isa book, has isbn-13 "9780008627843"; $promotion isa promotion, has name "Holiday Sale 2023"; insert $inclusion isa promotion-inclusion, links (promotion: $promotion, item: $book), has discount 0.25;end; +match $book isa book, has isbn-13 "9780500026557"; $promotion isa promotion, has name "Holiday Sale 2023"; insert $inclusion isa promotion-inclusion, links (promotion: $promotion, item: $book), has discount 0.25;end; diff --git a/guides/modules/ROOT/attachments/bookstore-schema.tql b/guides/modules/ROOT/attachments/bookstore-schema.tql new file mode 100644 index 000000000..6da6ad7f3 --- /dev/null +++ b/guides/modules/ROOT/attachments/bookstore-schema.tql @@ -0,0 +1,300 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +define + +entity book @abstract, + owns isbn @card(0..2), + owns isbn-13 @key, + owns isbn-10 @unique, + owns title, + owns page-count, + owns genre @card(0..), + owns price, + plays contribution:work, + plays publishing:published, + plays promotion-inclusion:item, + plays order-line:item, + plays rating:rated, + plays recommendation:recommended; + +entity hardback sub book, + owns stock; + +entity paperback sub book, + owns stock; + +entity ebook sub book; + +entity contributor, + owns name, + plays contribution:contributor, + plays authoring:author, + plays editing:editor, + plays illustrating:illustrator; + +entity company @abstract, + owns name; + +entity publisher sub company, + plays publishing:publisher; + +entity courier sub company, + plays delivery:deliverer; + +entity publication, + owns year, + plays publishing:publication, + plays locating:located; + +entity user, + owns id @key, + owns name, + owns birth-date, + owns total-spending, + owns loyalty-tier, + plays action-execution:executor, + plays locating:located, + plays recommendation:recipient; + +entity order, + owns id @key, + owns status, + plays order-line:order, + plays action-execution:action, + plays delivery:delivered; + +entity promotion, + owns code @key, + owns name, + owns start-timestamp, + owns end-timestamp, + plays promotion-inclusion:promotion; + +entity review, + owns id @key, + owns score, + owns verified, + plays rating:review, + plays action-execution:action; + +entity login, + owns success, + plays action-execution:action; + +entity address, + owns street, + plays delivery:destination, + plays locating:located; + +entity place @abstract, + owns name, + plays locating:located, + plays locating:location; + +entity city sub place; + +entity state sub place; + +entity country sub place; + +relation contribution, + relates contributor, + relates work; + +relation authoring sub contribution, + relates author as contributor; + +relation editing sub contribution, + relates editor as contributor; + +relation illustrating sub contribution, + relates illustrator as contributor; + +relation publishing, + relates publisher, + relates published, + relates publication; + +relation promotion-inclusion, + relates promotion, + relates item, + owns discount; + +relation order-line, + relates order, + relates item, + owns quantity; + +relation rating, + relates review, + relates rated; + +relation action-execution, + relates action, + relates executor, + owns timestamp; + +relation delivery, + relates deliverer, + relates delivered, + relates destination; + +relation locating, + relates located, + relates location; + +relation recommendation, + relates recommended, + relates recipient; + +attribute isbn @abstract, value string; +attribute isbn-13 sub isbn; +attribute isbn-10 sub isbn; +attribute title, value string; +attribute page-count, value integer; +attribute genre, value string; +attribute stock, value integer; +attribute price, value double; +attribute discount, value double; +attribute id, value string; +attribute code, value string; +attribute name, value string; +attribute birth-date, value datetime; +attribute street, value string; +attribute year, value integer; +attribute quantity, value integer; +attribute score, value integer; +attribute verified, value boolean; +attribute timestamp, value datetime; +attribute start-timestamp, value datetime; +attribute end-timestamp, value datetime; +attribute status, value string @values("invalid", "pending", "paid", "dispatched", "delivered", "returned", "canceled"); +attribute success, value boolean; +attribute total-spending, value double; +attribute loyalty-tier, value integer @range(0..5); + +# TODO: Change to check +fun is_review_verified_by_purchase($review: review) -> { order }: + match + ($review, $product) isa rating; + ($order, $product) isa order-line; + ($user, $review) isa action-execution, has timestamp $review-time; + ($user, $order) isa action-execution, has timestamp $order-time; + $review-time > $order-time; + return { $order }; + +fun book_recommendations_for($user: user) -> {book}: + match + $new-book isa book; + { + let $new-book in book_recommendations_by_author($user); + } or { + let $new-book in book_recommendations_by_genre($user); + }; + return { $new-book }; + +fun book_recommendations_by_genre($user: user) -> { book }: +match + $user isa user; + $liked-book isa book; + { + ($user, $order-for-liked) isa action-execution; + ($order-for-liked, $liked-book) isa order-line; + } or { + ($user, $review-for-liked) isa action-execution; + ($review-for-liked, $liked-book) isa rating; + $review-for-liked has score >= 7; + }; + $new-book isa book; + not { { + ($user, $order-for-new) isa action-execution; + ($order-for-new, $new-book) isa order-line; + } or { + ($user, $review-for-new) isa action-execution; + ($review-for-new, $new-book) isa rating; + }; }; + $liked-book has genre $shared-genre; + $new-book has genre $shared-genre; + not { { + $shared-genre == "fiction"; + } or { + $shared-genre == "nonfiction"; + }; }; + return { $new-book }; + +fun book_recommendations_by_author($user: user) -> { book }: + match + $user isa user; + $liked-book isa book; + { + ($user, $order-for-liked) isa action-execution; + ($order-for-liked, $liked-book) isa order-line; + } or { + ($user, $review-for-liked) isa action-execution; + ($review-for-liked, $liked-book) isa rating; + $review-for-liked has score >= 7; + }; + $new-book isa book; + not { { + ($user, $order-for-new) isa action-execution; + ($order-for-new, $new-book) isa order-line; + } or { + ($user, $review-for-new) isa action-execution; + ($review-for-new, $new-book) isa rating; + }; }; + ($liked-book, $shared-author) isa authoring; + ($new-book, $shared-author) isa authoring; + return { $new-book }; + +fun order_line_best_price($line: order-line) -> { double }: + match + ($order) isa action-execution, has timestamp $order-time; + $line isa order-line, links ($order, $item); + $item has price $retail-price; + let $time_value = $order-time; + let $best-discount = best_discount_for_item($item, $time_value); + let $discounted-price = round(100 * $retail-price * (1 - $best-discount)) / 100; + $line has quantity $quantity; + let $line-total = $quantity * $discounted-price; + return { $line-total }; + +fun best_discount_for_item($item: book, $order-time: datetime) -> double: + match + { + $inclusion isa promotion-inclusion, + links ($promotion, $item), + has discount $discount-attr; + $promotion has start-timestamp <= $order-time, + has end-timestamp >= $order-time; + let $discount = $discount-attr; + } or { + let $discount = 0.0; # default + }; +return max($discount); + +fun transitive_places($place: place) -> { place }: + match + { + locating (located: $place, location: $parent); + } or { + locating (located: $place, location: $middle); + let $parent in transitive_places($middle); + }; + return { $parent }; diff --git a/tutorials/modules/ROOT/nav.adoc b/guides/modules/ROOT/nav.adoc similarity index 80% rename from tutorials/modules/ROOT/nav.adoc rename to guides/modules/ROOT/nav.adoc index b064d3446..373116d85 100644 --- a/tutorials/modules/ROOT/nav.adoc +++ b/guides/modules/ROOT/nav.adoc @@ -1,3 +1,3 @@ -// Tutorials +// Guides include::{page-version}@home::partial$nav-main.adoc[] diff --git a/guides/modules/ROOT/pages/index.adoc b/guides/modules/ROOT/pages/index.adoc new file mode 100644 index 000000000..a40b6e4ee --- /dev/null +++ b/guides/modules/ROOT/pages/index.adoc @@ -0,0 +1,25 @@ += Guides + +In this section, you will find guides for accomplishing specific TypeDB tasks. + +**New users** - We recommend new users begin with the xref:{page-version}@home::get-started/index.adoc[get started] guide +in the home section. + +[cols-2] +-- +.xref:{page-version}@guides::integrations/index.adoc[] +[.clickable] +**** +Integrate TypeDB into your application or platform +**** + +.xref:{page-version}@guides::typeql/index.adoc[] +[.clickable] +**** +Learn how to write TypeQL queries +**** +-- + +Got other guides you'd like to see? +Get in touch at link:mailto:community@typedb.com?subject=Request%20new%20guide[community@typedb.com] +or link:https://typedb.com/discord[join our discord server]. diff --git a/tutorials/modules/ROOT/pages/deploy-through-api.adoc b/guides/modules/ROOT/pages/integrations/deploy-through-api.adoc similarity index 98% rename from tutorials/modules/ROOT/pages/deploy-through-api.adoc rename to guides/modules/ROOT/pages/integrations/deploy-through-api.adoc index be8c664e2..a8b8e6d0d 100644 --- a/tutorials/modules/ROOT/pages/deploy-through-api.adoc +++ b/guides/modules/ROOT/pages/integrations/deploy-through-api.adoc @@ -1,11 +1,11 @@ = Deploy TypeDB via the Cloud API -:keywords: typedb, typeql, tutorial, api, cloud, cluster, deploy +:keywords: typedb, typeql, tutorial, guide, api, cloud, cluster, deploy :pageTitle: Deploy TypeDB via the Cloud API -:summary: A tutorial on deploying TypeDB through the API +:summary: A guide on deploying TypeDB through the API :page-toclevels: 2 :tabs-sync-option: -This tutorial will walk you through the creation of a script +This guide will walk you through the creation of a script to automate deployment of a TypeDB cluster on TypeDB Cloud. We're going to build a script that authenticates with the API, @@ -653,7 +653,7 @@ If successful, TypeDB Cloud will deploy your cluster, and the script will poll i == Conclusion -This tutorial has shown you how to set up a script to deploy TypeDB through the Cloud API. +This guide has shown you how to set up a script to deploy TypeDB through the Cloud API. Similar approaches can be used for other common actions, such as pausing or resuming your clusters when not in use. diff --git a/guides/modules/ROOT/pages/integrations/index.adoc b/guides/modules/ROOT/pages/integrations/index.adoc new file mode 100644 index 000000000..983bb4747 --- /dev/null +++ b/guides/modules/ROOT/pages/integrations/index.adoc @@ -0,0 +1,18 @@ += Integrations + +In this section, you will find guides for integrating TypeDB with other tools and platforms. + +[cols-2] +-- +.xref:{page-version}@guides::integrations/deploy-through-api.adoc[] +[.clickable] +**** +Set up a script for launching TypeDB from the TypeDB Cloud API +**** + +.xref:{page-version}@guides::integrations/use-github-actions.adoc[] +[.clickable] +**** +Run TypeDB from your GitHub Actions CI pipeline +**** +-- diff --git a/tutorials/modules/ROOT/pages/use-github-actions.adoc b/guides/modules/ROOT/pages/integrations/use-github-actions.adoc similarity index 93% rename from tutorials/modules/ROOT/pages/use-github-actions.adoc rename to guides/modules/ROOT/pages/integrations/use-github-actions.adoc index f219951a0..e62bd6386 100644 --- a/tutorials/modules/ROOT/pages/use-github-actions.adoc +++ b/guides/modules/ROOT/pages/integrations/use-github-actions.adoc @@ -1,10 +1,10 @@ = Use TypeDB in GitHub Actions -:keywords: typedb, typeql, tutorial, github actions, ci +:keywords: typedb, typeql, tutorial, guide, github actions, ci :pageTitle: Use TypeDB in GitHub Actions -:summary: A tutorial on using the TypeDB in GitHub Actions +:summary: A guide on using the TypeDB in GitHub Actions :page-toclevels: 2 -This tutorial shows you how to get a running instance of TypeDB into your GitHub Actions CI pipeline +This guide shows you how to get a running instance of TypeDB into your GitHub Actions CI pipeline using the TypeDB GitHub Action. == Step 1. Install and run TypeDB diff --git a/guides/modules/ROOT/pages/typeql/advanced-pipelines.adoc b/guides/modules/ROOT/pages/typeql/advanced-pipelines.adoc new file mode 100644 index 000000000..f9f98a101 --- /dev/null +++ b/guides/modules/ROOT/pages/typeql/advanced-pipelines.adoc @@ -0,0 +1,181 @@ += Advanced query pipelines +:keywords: typedb, typeql, tutorial, guide, console +:pageTitle: +:summary: +:page-toclevels: 2 +:tabs-sync-option: +:test-typeql: linear + +== Overview + +In this guide, we will explore some more complex pipelines and patterns in TypeQL. + +== Prerequisites + +This guide assumes you have access to a running TypeDB instance, as well as a TypeDB Console. + +We recommend xref:{page-version}@home::install/ce.adoc[installing TypeDB Community Edition] as it is distributed bundled with Console for easy setup. + +This is a continuation of xref:{page-version}@guides::typeql/read-data.adoc[] and xref:{page-version}@guides::typeql/insert-update-data.adoc[], though you don't need to have completed them to follow along. + +== Example schema and data + +We are using the https://github.com/typedb/typedb-examples/tree/master/use-cases/bookstore[bookstore example] schema and data throughout this guide. +You can load the example into your TypeDB instance using the following Console command: + +[,console] +---- +database create-init bookstore https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-schema.tql https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-data.tql +---- + +.Full schema and data queries +[%collapsible] +==== +[,typeql] +---- +#!test[schema, commit] +include::{page-version}@guides::attachment$bookstore-schema.tql[lines=20..] +---- +[,typeql] +---- +#!test[write, commit] +include::{page-version}@guides::attachment$bookstore-data.tql[lines=18..] +---- +==== + +== Set order status based on stock using `or` + +Let's say we want to create an order for a user, but we want to check the book is in stock first. +If it isn't, we need to mark the order as invalid. + +We can do this by using an `or` to check if the book is in stock or not and setting `$status` accordingly. + +[,typeql] +---- +#!test[write, rollback, count = 1] +match + $book isa book, has isbn-13 "9780451162076"; + { + $book has stock >= 1; + let $status = "pending"; + } or { + $book has stock < 1; + let $status = "invalid"; + }; +insert + $order isa order, + has id "o0067", + has status == $status; + $line isa order-line, + links (order: $order, item: $book), + has quantity 1; +---- + +== Group sales statistics by genre using `reduce` with `groupby` + +We can use a reduce stage to collect sales statistics for each genre within a given year. + +The `groupby` keyword allows us to sum the sale quantities grouped by the value of a specific variable, in this case `$genre`. + +[,typeql] +---- +#!test[write, rollback, count = 8] +match + $item isa book, has genre $genre; + order-line ($order, $item), has quantity $quantity; + action-execution ($order), has timestamp $timestamp; + $timestamp >= 2022-01-01T00:00; + $timestamp < 2023-01-01T00:00; +reduce + $total-sold = sum($quantity) groupby $genre; +fetch { + "genre": $genre, + "total sold": $total-sold +}; +---- + +Note that when a book has multiple genres, the number of times it has been sold is included in the results for each genre. + +[,json] +---- +{ + "genre": "historical fiction", + "total sold": 5 +} +{ + "total sold": 6, + "genre": "history" +} +{ + "total sold": 8, + "genre": "fiction" +} +... +Finished. Total answers: 8 +---- + +== Update user loyalty tier based on spending using `try` + +Imagine we want to update a user's loyalty tier based on their total spending. +After a user has paid for an order, we want to update their total spending and, if their spending has crossed some threshold, we want to increase their loyalty tier as well. + +We've covered in xref:{page-version}@guides::typeql/read-data.adoc#_fetch_discounted_price_with_optionals[Reading data] how to use a `try` pattern to assign a variable based on whether the data +exists in the database. +This extends to all kinds of patterns, including comparisons. +All patterns in a `try` block must succeed, otherwise the new variables defined in it will not be assigned. + +We can use a `try` pattern to only assign the `$new-loyalty-tier` when the user's total spending has exceeded the threshold. +Then, we can use the `try` keyword to conditionally set their loyalty tier in the `update` stage. +The `try` block in the `update` stage will only be executed if the `$new-loyalty-tier` is assigned. + +[,typeql] +---- +#!test[write, rollback, count = 1] +match + $user isa user, has id "u0002", has total-spending $spending; + let $new-spending = $spending + 9.99; + try { + $user has loyalty-tier $tier; + $new-spending > 100 * $tier * $tier; + $tier < 5; + let $new-loyalty-tier = $tier + 1; + }; +update + $user has total-spending == $new-spending; + try { $user has loyalty-tier == $new-loyalty-tier; }; +---- + +== Further reading + +[cols-2] +-- +.xref:{page-version}@core-concepts::typeql/index.adoc[] +[.clickable] +**** +TypeQL core concepts +**** + +.xref:{page-version}@core-concepts::typeql/query-clauses.adoc[] +[.clickable] +**** +Learn more about chaining TypeQL clauses into pipelines +**** + +.xref:{page-version}@typeql-reference::patterns/disjunctions.adoc[] +[.clickable] +**** +`or` documentation in TypeQL reference +**** + +.xref:{page-version}@typeql-reference::pipelines/reduce.adoc +[.clickable] +**** +`reduce` documentation in TypeQL reference +**** + +.xref:{page-version}@typeql-reference::patterns/optionals.adoc +[.clickable] +**** +`try` documentation in TypeQL reference +**** +-- diff --git a/guides/modules/ROOT/pages/typeql/index.adoc b/guides/modules/ROOT/pages/typeql/index.adoc new file mode 100644 index 000000000..9907fb57e --- /dev/null +++ b/guides/modules/ROOT/pages/typeql/index.adoc @@ -0,0 +1,30 @@ += TypeQL + +This section contains guides for TypeQL, TypeDB query language. + +[cols-2] +-- +.xref:{page-version}@guides::typeql/read-data.adoc[] +[.clickable] +**** +Read data from TypeDB +**** + +.xref:{page-version}@guides::typeql/insert-update-data.adoc[] +[.clickable] +**** +Write and update data in TypeDB +**** + +.xref:{page-version}@guides::typeql/advanced-pipelines.adoc[] +[.clickable] +**** +Advanced TypeDB pipelines and patterns +**** + +.xref:{page-version}@guides::typeql/sql-vs-typeql.adoc[] +[.clickable] +**** +A guide of relational constructs in SQL compared to similar concepts in TypeQL. +**** +-- diff --git a/guides/modules/ROOT/pages/typeql/insert-update-data.adoc b/guides/modules/ROOT/pages/typeql/insert-update-data.adoc new file mode 100644 index 000000000..bda1f6540 --- /dev/null +++ b/guides/modules/ROOT/pages/typeql/insert-update-data.adoc @@ -0,0 +1,320 @@ += Inserting and updating data +:keywords: typedb, typeql, tutorial, guide, console, crud +:pageTitle: +:summary: +:page-toclevels: 2 +:tabs-sync-option: +:test-typeql: linear + +== Overview + +This guide covers the basics of inserting and updating data in TypeDB. + +== Prerequisites + +This guide assumes you have access to a running TypeDB instance, as well as a TypeDB Console. + +We recommend xref:{page-version}@home::install/ce.adoc[installing TypeDB Community Edition] as it is distributed bundled with Console for easy setup. + +This is a continuation of xref:{page-version}@guides::typeql/read-data.adoc[], though you don't need to have completed it to follow along. + +== Example schema and data + +We are using the https://github.com/typedb/typedb-examples/tree/master/use-cases/bookstore[bookstore example] schema and data throughout this guide. +You can load the example into your TypeDB instance using the following Console command: + +[,console] +---- +database create-init bookstore https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-schema.tql https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-data.tql +---- + +.Full schema and data queries +[%collapsible] +==== +[,typeql] +---- +#!test[schema, commit] +include::{page-version}@guides::attachment$bookstore-schema.tql[lines=20..] +---- +[,typeql] +---- +#!test[write, commit] +include::{page-version}@guides::attachment$bookstore-data.tql[lines=18..] +---- +==== + +== Add a book to the database with `insert` + +To add a new book to the database, we can use an `insert` query. +Simply use an `isa` statement to specify the type of the entity, and then use `has` statements to list the attributes of the book. + +[,typeql] +---- +#!test[write, count = 1, rollback] +insert + $book isa paperback, + has isbn-13 "9780441569595", + has isbn-10 "0441569595", + has title "Neuromancer", + has stock 5; +---- + +Adding the author is as simple as inserting a `contributor` entity in a similar fashion, and an `authoring` relation linking the two. + +[,typeql] +---- +#!test[write, count = 1, commit] +insert + $book isa paperback, + has isbn-13 "9780441569595", + has isbn-10 "0441569595", + has title "Neuromancer", + has stock 5; + $author isa contributor, + has name "Gibson, William"; + authoring (work: $book, author: $author); +---- + +What if the author already exists? +The query above would then merrily insert another `contributor` with the same name, which is almost certainly not what we intend. + +Thankfully, the fix is straightforward. +We can use a `match` clause to find the author, and then use an `insert` clause to create the book and the authoring relation. + +[,typeql] +---- +#!test[write, count = 1, rollback] +match + $author isa contributor, + has name "Adams, Douglas"; +insert + $book isa paperback, + has isbn-13 "9781529034585", + has isbn-10 "1529034582", + has title "Dirk Gently's Holistic Detective Agency", + has stock 4; + authoring (work: $book, author: $author); +---- + +== Insert an author only if one doesn't exist with `put` + +We happened to know that an author named "Adams, Douglas" was already present in the database. +What if we didn't know that, but still wanted to avoid inserting a duplicate author? +We can use a `put` clause to insert the author only if it does not already exist in the database. + +[,typeql] +---- +#!test[write, count = 1, rollback] +put + $author isa contributor, + has name "Adams, Douglas"; +---- + +If there is no `contributor` with the name "Adams, Douglas", the `put` clause will insert a new one. +If there is, the `put` clause will not insert a new one, but instead retrieve the existing one. + +Either way, `$author` ends up being the `contributor` with the name "Adams, Douglas". +We can add the `insert` clause after the `put` to insert the book and the authoring relation in the same query. + +[,typeql] +---- +#!test[write, count = 1, rollback] +put + $author isa contributor, + has name "Adams, Douglas"; +insert + $book isa paperback, + has isbn-13 "9781529034585", + has isbn-10 "1529034582", + has title "Dirk Gently's Holistic Detective Agency", + has stock 4; + authoring (work: $book, author: $author); +---- + +[WARNING] +==== +It might be tempting to combine all of the above into one `put` query: + +[,typeql] +---- +#!test[write, count = 1, rollback] +put + $author isa contributor, + has name "Adams, Douglas"; + $book isa paperback, + has isbn-13 "9781529034585", + has isbn-10 "1529034582", + has title "Dirk Gently's Holistic Detective Agency", + has stock 4; + authoring (work: $book, author: $author); +---- + +Here we have `$author` and `$book` in the same `put` clause. +When you have two objects in a `put` query, if either of them is new, the other is also inserted. +In this case we end up with a duplicate author, an inconsistent state. + +In general, you should have one object in each `put` clause. +==== + +== Remove a book from an order with `delete` + +In the bookstore example, a user's order is represented as an entity with an `order-line` relation connecting it to each item ordered, along with the quantity ordered. + +[,typeql] +---- +define + +entity book @abstract, + plays order-line:item; + +entity order, + plays order-line:order; + +relation order-line, + relates order, + relates item, + owns quantity; +---- + +Deleting a book from an order is as simple as deleting the `order-line` relation between the two. + +[,typeql] +---- +#!test[write, count = 1, rollback] +match + $order isa order, has id "o0001"; + $book isa book, has isbn-13 "9780393634563"; + $order-line isa order-line, links (order: $order, item: $book); +delete + $order-line; +---- + +== Delete an entire order with `delete` + +To delete an order, we need to delete the order entity and all of the `order-line` relations that link it to the books in the order. + +[,typeql] +---- +#!test[write, count = 2, rollback] +match + $order isa order, has id "o0001"; + $order-line isa order-line, links (order: $order); +delete + $order-line; + $order; +---- + +Note that deleting _just_ the order would not be enough. +The order would be deleted _from_ the `order-line` relations, but the relations themselves would remain. + +[TIP] +==== +There is a planned `@cascade` annotation coming soon in TypeDB. +When a role type is annotated with `@cascade`, deleting a player of that role would also automatically delete the relation that defines that role. + +[,typeql] +---- +define +relation order-line, + relates order @cascade, + relates item @cascade, + owns quantity; +---- + +`@cascade` is not yet implemented at the time of writing. +==== + +== Update stock with `update` + +When we sell a book, we need to decrease the stock by one. +To do that, we can retrieve the old stock of the book and then insert a new attribute with the decreased value. + +[,typeql] +---- +#!test[write, count = 1, commit] +match + $book isa book, has isbn-13 "9780671461492", has stock $stock; + let $new-stock = $stock - 1; +update + $book has stock == $new-stock; +---- + +`update` acts as a shorthand for deleting the old `stock` attribute and inserting a new one with the updated value. +It could equivalently be written as follows: + +[,typeql] +---- +#!test[write, count = 1, commit] +match + $book isa book, has isbn-13 "9780671461492", has stock $stock; + let $new-stock = $stock - 1; +delete + has $stock of $book; +insert + $book has stock == $new-stock; +---- + +== Update book's genre with `delete` and `insert` + +Attribute ownerships in TypeDB can have cardinality annotations that specify how many of that attribute an object is allowed to own. + +By default, all attributes have cardinality `0..1`, that is to say an object can own at most one attribute of that type. + +`update` is only allowed when the upper bound of the attribute cardinality is one. +This is to avoid ambiguity: there's at most one old attribute to delete. + +If you define an attribute ownership with higher cardinality, you will not be able to use `update` even if the object happens to only have zero or one attribute of the type. +Since a book may have more than one genre, such as "fiction" and "science fiction", we cannot use `update` to change the genre of a book. + +[,typeql] +---- +#!test[write, count = 1, rollback] +match + $book isa book, has isbn-13 "9780671461492", has genre $genre; + $genre == "science fiction"; +delete + has $genre of $book; +insert + $book has genre "historical fiction"; +---- + +== Further reading + +[cols-2] +-- +.xref:{page-version}@guides::typeql/advanced-pipelines.adoc[] +[.clickable] +**** +Learn about complex pipelines in the next guide +**** + +.xref:{page-version}@core-concepts::typeql/index.adoc[] +[.clickable] +**** +TypeQL core concepts +**** + +.xref:{page-version}@typeql-reference::pipelines/insert.adoc[] +[.clickable] +**** +`insert` documentation in TypeQL reference +**** + +.xref:{page-version}@typeql-reference::pipelines/put.adoc[] +[.clickable] +**** +`put` documentation in TypeQL reference +**** + +.xref:{page-version}@typeql-reference::pipelines/delete.adoc[] +[.clickable] +**** +`delete` documentation in TypeQL reference +**** + +.xref:{page-version}@typeql-reference::pipelines/update.adoc[] +[.clickable] +**** +`update` documentation in TypeQL reference +**** +-- diff --git a/guides/modules/ROOT/pages/typeql/read-data.adoc b/guides/modules/ROOT/pages/typeql/read-data.adoc new file mode 100644 index 000000000..1ae42415b --- /dev/null +++ b/guides/modules/ROOT/pages/typeql/read-data.adoc @@ -0,0 +1,392 @@ += Reading data +:keywords: typedb, typeql, tutorial, guide, console +:pageTitle: +:summary: +:page-toclevels: 2 +:tabs-sync-option: +:test-typeql: linear + +== Overview + +This guide covers the common patterns of read queries in TypeQL. + +== Prerequisites + +This guide assumes you have access to a running TypeDB instance, as well as a TypeDB Console. + +We recommend xref:{page-version}@home::install/ce.adoc[installing TypeDB Community Edition] as it is distributed bundled with Console for easy setup. + +== Example schema and data + +We are using the https://github.com/typedb/typedb-examples/tree/master/use-cases/bookstore[bookstore example] schema and data throughout this guide. +You can load the example into your TypeDB instance using the following Console command: + +[,console] +---- +database create-init bookstore https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-schema.tql https://github.com/typedb/typedb-examples/releases/download/3.7.0/bookstore-data.tql +---- + +.Full schema and data queries +[%collapsible] +==== +[,typeql] +---- +#!test[schema, commit] +include::{page-version}@guides::attachment$bookstore-schema.tql[lines=20..] +---- +[,typeql] +---- +#!test[write, commit] +include::{page-version}@guides::attachment$bookstore-data.tql[lines=18..] +---- +==== + +== List all books + +To retrieve all ``book``s in the database, use a xref:{page-version}@typeql-reference::pipelines/match.adoc[`match`] query with an xref:{page-version}@typeql-reference::statements/isa.adoc[`isa`] +statement: + +[,typeql] +---- +#!test[read, count = 21] +match $book isa book; +---- + +This produces an output containing just the unique internal identifiers of all the books in the database alongside their exact type: + +[,typeql] +---- + ----------- + $book | isa hardback, iid 0x1e00010000000000000000 + ----------- + $book | isa hardback, iid 0x1e00010000000000000001 + ----------- + $book | isa hardback, iid 0x1e00010000000000000002 + ----------- + ... +Finished. Total answers: 21 +---- + +These are the values the variable `$book` takes that can be used further down in the query. +This output isn't very useful for displaying a list of books to the customer, however. +Instead, most read queries end with a `fetch` clause that allows you to format the query result into a JSON-like document: + +[,typeql] +---- +#!test[read, count = 21] +match + $book isa book; +fetch { + $book.* +}; +---- + +This is the simplest `fetch` clause there is, and it simply retrieves all attributes `$book` owns: + +[,json] +---- +{ + "isbn-10": "0671461494", + "title": "The Hitchhiker's Guide to the Galaxy", + "genre": [ + "fiction", + "science fiction" + ], + "stock": 9, + "price": 91.47, + "page-count": 215, + "isbn-13": "9780671461492" +} +... +Finished. Total answers: 21 +---- + +== Retrieve the author of each book using additional constraints + +Some data we'd like to display is still missing, however, such as the book's author. +Let's look back at the schema and find out how the author is associated to the book. + +[,typeql] +---- +define + +entity book @abstract, + plays contribution:work; + +entity contributor, + owns name, + plays contribution:contributor, + plays authoring:author, + plays editing:editor, + plays illustrating:illustrator; + +relation contribution, + relates contributor, + relates work; + +relation authoring sub contribution, + relates author as contributor; + +relation editing sub contribution, + relates editor as contributor; + +relation illustrating sub contribution, + relates illustrator as contributor; +---- + +We can see that the author is not an attribute of a book, but rather a separate entity that is linked to the book through an `authoring` relation. +We'll adjust the query. + +[,typeql] +---- +#!test[read, count = 23] +match + $book isa book; + authoring (author: $author, work: $book); +fetch { + "book": { $book.* }, + "author": { $author.* } +}; +---- + +We've added a new pattern to the query that matches an `authoring` relation in which the `$book` is playing the `work` role, and binds whichever entity is playing the `author` role in it to the +variable `$author`. + +[,json] +---- +{ + "author": { + "name": "Adams, Douglas" + }, + "book": { + "price": 91.47, + "stock": 9, + "isbn-10": "0671461494", + "genre": [ + "fiction", + "science fiction" + ], + "page-count": 215, + "title": "The Hitchhiker's Guide to the Galaxy", + "isbn-13": "9780671461492" + } +} +... +Finished. Total answers: 23 +---- + +If we want to clean up the output to only fetch the attributes we want to display, we can use explicit attribute retrieval: + +[,typeql] +---- +#!test[read, count = 23] +match + $book isa book; + authoring (author: $author, work: $book); +fetch { + "title": $book.title, + "price": $book.price, + "author": $author.name +}; +---- + +[,json] +---- +{ + "price": 91.47, + "author": "Adams, Douglas", + "title": "The Hitchhiker's Guide to the Galaxy" +} +{ + "price": 34.98, + "title": "Classical Mythology", + "author": "Morford, Mark P. O." +} +{ + "price": 34.98, + "title": "Classical Mythology", + "author": "Lenardon, Robert J." +} +... +Finished. Total answers: 23 +---- + +== Fetch list of authors using a subquery + +Have you noticed? +The last query we ran returned two more answers, 23 total, compared to the 21 answers to the query before. +Turns out, some books have more than one author, such as "Classical Mythology" seen in the output above. +Other books, like "Great Discoveries in Medicine", have no author listed at all, only editors, so they are gone from the output completely! + +There is no error here: we've asked for pairs of `$book, $author` that are linked by an `authoring` relation, and TypeDB obliged. + +We'll need to be able to include all the authors of the book in the output as a list (which may be empty). +We can do this by using a subquery in the `fetch`: + +[,typeql] +---- +#!test[read, count = 21] +match + $book isa book; +fetch { + "title": $book.title, + "price": $book.price, + "authors": [ + match + authoring (author: $author, work: $book); + $author has name $author-name; + return { $author-name }; + ] +}; +---- + +You can see we've moved the `authoring` relation to the subquery, and we've explicitly queried for the name attribute of the author. +The query is wrapped in square brackets `[]` to indicate that we want the results of the query collected into an array. +The `return` statement tells TypeDB which variables to return (`$author-name`) + +The curly braces `{}` are a requirement for a subquery that returns more than one answer. +If you want _an_ author, for instance, you can replace the return body with `first $author-name`, for instance. +In that case, the `[]` around the query should be substituted with parentheses `()` so `fetch` does not collect the single answer into an array of one. + +The `return` syntax in subqueries is shared with xref:{page-version}@typeql-reference::functions/writing.adoc[functions]. +You can read more about using functions in xref:{page-version}@core-concepts::typeql/queries-as-functions.adoc[] in TypeQL Core Concepts. + +[,json] +---- +{ + "price": 34.98, + "authors": [ + "Morford, Mark P. O.", + "Lenardon, Robert J." + ], + "title": "Classical Mythology" +} +{ + "title": "The Hitchhiker's Guide to the Galaxy", + "price": 91.47, + "authors": [ + "Adams, Douglas" + ] +} +... +Finished. Total answers: 21 +---- + +== Fetch discounted price with optionals + +Sometimes the data we want to display is optional, and we'd like to display it if it exists, but not require it to match for the query to succeed. + +For instance, we might want to display the discounted price of a book if it is currently on sale. +If we try to add a pattern to the query that matches a `promotion-inclusion` relation, the query will only return books that are on sale: + +[,typeql] +---- +#!test[read, count = 5] +match + $book isa book, has price $book-price; + promotion-inclusion (item: $book), has discount $discount; + let $discounted-price = $book-price * (1.0 - $discount); +fetch { + "title": $book.title, + "price": $book-price, + "discounted-price": $discounted-price, +}; +---- + +[,json] +---- +{ + "title": "Dune", + "discounted-price": 4.1175, + "price": 5.49 +} +{ + "price": 16.99, + "discounted-price": 12.7425, + "title": "The Hobbit" +} +... +Finished. Total answers: 5 +---- + +Instead, we'd like to display the discounted price if it exists, but not _require_ it to match for the query to succeed. +We can do this by using a `try` pattern: + +[,typeql] +---- +#!test[read, count = 21] +match + $book isa book, has price $book-price; + try { + promotion-inclusion (item: $book), has discount $discount; + let $discounted-price = $book-price * (1.0 - $discount); + }; +fetch { + "title": $book.title, + "price": $book-price, + "discounted-price": $discounted-price, +}; +---- + +[,json] +---- +{ + "discounted-price": null, + "price": 91.47, + "title": "The Hitchhiker's Guide to the Galaxy" +} +{ + "price": 16.99, + "discounted-price": 12.7425, + "title": "The Hobbit" +} +... +Finished. Total answers: 21 +---- + +[TIP] +==== +Note that a `fetch` subquery is not required to produce an answer for the query to succeed. +If the subquery does not match any data, the `fetch` document contains an empty list or a `null` for that key. +The previous query could be equivalently written as: + +[,typeql] +---- +#!test[read, count = 21] +match + $book isa book, has price $book-price; +fetch { + "title": $book.title, + "price": $book-price, + "discounted-price": ( + match + promotion-inclusion (item: $book), has discount $discount; + let $discounted-price = $book-price * (1.0 - $discount); + return first $discounted-price; + ) +}; +---- +==== + +== Further reading + +[cols-2] +-- +.xref:{page-version}@guides::typeql/insert-update-data.adoc[] +[.clickable] +**** +Learn how to modify data in the next guide +**** + +.xref:{page-version}@core-concepts::typeql/index.adoc[] +[.clickable] +**** +TypeQL core concepts +**** + +.xref:{page-version}@typeql-reference::index.adoc[] +[.clickable] +**** +TypeQL reference manual +**** +-- diff --git a/core-concepts/modules/ROOT/pages/typeql/sql-vs-typeql.adoc b/guides/modules/ROOT/pages/typeql/sql-vs-typeql.adoc similarity index 100% rename from core-concepts/modules/ROOT/pages/typeql/sql-vs-typeql.adoc rename to guides/modules/ROOT/pages/typeql/sql-vs-typeql.adoc diff --git a/guides/modules/ROOT/partials/nav.adoc b/guides/modules/ROOT/partials/nav.adoc new file mode 100644 index 000000000..2627e018a --- /dev/null +++ b/guides/modules/ROOT/partials/nav.adoc @@ -0,0 +1,10 @@ +.xref:{page-version}@guides::index.adoc[] + +* xref:{page-version}@guides::integrations/index.adoc[] +** xref:{page-version}@guides::integrations/deploy-through-api.adoc[] +** xref:{page-version}@guides::integrations/use-github-actions.adoc[] + +* xref:{page-version}@guides::typeql/index.adoc[] +** xref:{page-version}@guides::typeql/read-data.adoc[] +** xref:{page-version}@guides::typeql/insert-update-data.adoc[] +** xref:{page-version}@guides::typeql/advanced-pipelines.adoc[] diff --git a/home/modules/ROOT/pages/learning-journey.adoc b/home/modules/ROOT/pages/learning-journey.adoc index dea694faf..3c9ed8069 100644 --- a/home/modules/ROOT/pages/learning-journey.adoc +++ b/home/modules/ROOT/pages/learning-journey.adoc @@ -37,7 +37,7 @@ skip to the next section and come back to the examples afterward! == Step 5: Tutorials -Look at our xref:{page-version}@tutorials::index.adoc[tutorials] for accomplishing specific TypeDB tasks, +Look at our xref:{page-version}@guides::index.adoc[guides] for accomplishing specific TypeDB tasks, such as using TypeDB in CI, or deploying TypeDB through our Cloud API. == Step 6: Core concepts diff --git a/home/modules/ROOT/partials/nav-main.adoc b/home/modules/ROOT/partials/nav-main.adoc index 0a639f522..093ad41b4 100644 --- a/home/modules/ROOT/partials/nav-main.adoc +++ b/home/modules/ROOT/partials/nav-main.adoc @@ -2,7 +2,7 @@ include::{page-version}@home::partial$nav.adoc[] include::{page-version}@examples::partial$nav.adoc[] -include::{page-version}@tutorials::partial$nav.adoc[] +include::{page-version}@guides::partial$nav.adoc[] include::{page-version}@core-concepts::partial$nav.adoc[] diff --git a/test/code/main.py b/test/code/main.py index d09b55562..b0fa30d88 100644 --- a/test/code/main.py +++ b/test/code/main.py @@ -23,6 +23,7 @@ "home": os.path.join(os.path.dirname(__file__), "../../home/modules/ROOT"), "examples": os.path.join(os.path.dirname(__file__), "../../examples/modules/ROOT"), + "guides": os.path.join(os.path.dirname(__file__), "../../guides/modules/ROOT"), "maintenance-operation": os.path.join(os.path.dirname(__file__), "../../maintenance-operation/modules/ROOT"), "core-concepts": os.path.join(os.path.dirname(__file__), "../../core-concepts/modules/ROOT"), "tools": os.path.join(os.path.dirname(__file__), "../../tools/modules/ROOT"), diff --git a/test/code/parser/parser.py b/test/code/parser/parser.py index 5eaea47ff..c54b9245a 100644 --- a/test/code/parser/parser.py +++ b/test/code/parser/parser.py @@ -1,7 +1,7 @@ import os import re from dataclasses import dataclass -from typing import List, Dict +from typing import List, Dict, Tuple import logging logger = logging.getLogger('main') # To see debug log, set logging level to debug in main.py @@ -114,9 +114,17 @@ def retrieve_antora_include(self, include_str: str): if tags_match.startswith('tags='): tags = tags_match.split('=')[1].split(';') + line_nrs: Tuple[str, str] = (None, None) + if tags_match.startswith('lines='): + line_nrs = tags_match.split('=')[1].split('..') + # Read tagged lines from Antora include with open(file_path, 'r', encoding='utf-8') as f: lines = f.readlines() + if line_nrs[1]: + lines = lines[:int(line_nrs[1])] + if line_nrs[0]: + lines = lines[int(line_nrs[0]) - 1:] tagged_lines: Dict[str, List[str]] = {} current_tag = None @@ -148,10 +156,13 @@ def retrieve_antora_include(self, include_str: str): logging.debug(f"... finished scanning included file, resolved tags: {tagged_lines}") output_lines = [] - for tag in tags: - if tagged_lines.get(tag) is None: - self.error(f"Include is missing tag {tag}") - output_lines += tagged_lines[tag] + if tags: + for tag in tags: + if tagged_lines.get(tag) is None: + self.error(f"Include is missing tag {tag}") + output_lines += tagged_lines[tag] + else: + output_lines = lines return output_lines diff --git a/test/code/runners/typeql_runner.py b/test/code/runners/typeql_runner.py index b2b633a3b..62d5e6c47 100644 --- a/test/code/runners/typeql_runner.py +++ b/test/code/runners/typeql_runner.py @@ -3,6 +3,7 @@ from enum import Enum from typing import List, Dict, Tuple, Union from test.code.parser.parser import ParsedTest +import re import logging logger = logging.getLogger('main') # To see debug log, set logging level to debug in main.py @@ -93,6 +94,7 @@ def run_failing_queries(self, queries: List[str], type: TransactionType) -> str: return FailureMode.NoFailure def run_transaction(self, queries: List[str], type: TransactionType, rollback=False) -> Union[int, None]: + queries = [q for qs in queries for q in re.split(r'\bend\s*;', qs) if q.strip()] with self.driver.transaction(self.db, type) as tx: try: for q in queries: @@ -236,4 +238,4 @@ def try_tests(self, parsed_tests: List[ParsedTest], adoc_path: str, file_config: current_test_index += 1 - return None \ No newline at end of file + return None diff --git a/test/content/antora-playbook-mock-for-ci.yml b/test/content/antora-playbook-mock-for-ci.yml index e68d5e9d0..8de9a89da 100644 --- a/test/content/antora-playbook-mock-for-ci.yml +++ b/test/content/antora-playbook-mock-for-ci.yml @@ -30,7 +30,7 @@ content: start_path: typeql-reference branches: HEAD - url: ./../.. - start_path: tutorials + start_path: guides branches: HEAD - url: ./../.. diff --git a/tutorials/modules/ROOT/pages/index.adoc b/tutorials/modules/ROOT/pages/index.adoc deleted file mode 100644 index e1fe27764..000000000 --- a/tutorials/modules/ROOT/pages/index.adoc +++ /dev/null @@ -1,25 +0,0 @@ -= Tutorials - -In this section, you will find tutorials for accomplishing specific TypeDB tasks. - -**New users** - We recommend new users begin with the xref:{page-version}@home::get-started/index.adoc[get started] guide -in the home section. - -[cols-2] --- -.xref:{page-version}@tutorials::deploy-through-api.adoc[] -[.clickable] -**** -Set up a script for launching TypeDB from the TypeDB Cloud API -**** - -.xref:{page-version}@tutorials::use-github-actions.adoc[] -[.clickable] -**** -Run TypeDB from your GitHub Actions CI pipeline -**** --- - -Got other tutorials you'd like to see? -Get in touch at link:mailto:community@typedb.com?subject=Request%20new%20tutorial[community@typedb.com] -or link:https://typedb.com/discord[join our discord server]. diff --git a/tutorials/modules/ROOT/partials/nav.adoc b/tutorials/modules/ROOT/partials/nav.adoc deleted file mode 100644 index 3c06213d1..000000000 --- a/tutorials/modules/ROOT/partials/nav.adoc +++ /dev/null @@ -1,5 +0,0 @@ -.xref:{page-version}@tutorials::index.adoc[] - -* xref:{page-version}@tutorials::deploy-through-api.adoc[] -* xref:{page-version}@tutorials::use-github-actions.adoc[] -