Created
September 16, 2022 12:32
-
-
Save allochi/83af00947ac79a1bea7a9eb3a7bf8175 to your computer and use it in GitHub Desktop.
Sample graph query on SurrealDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- coffeeshops | |
CREATE coffeeshop:starbucks SET name='StarBucks'; | |
CREATE coffeeshop:boreal SET name='Boreal'; | |
-- beverages | |
CREATE beverage:tea SET name='Tea'; | |
CREATE beverage:latte SET name='Latte'; | |
CREATE beverage:caramel_macchiato SET name='Caramel Macchiato'; | |
CREATE beverage:coka_cola SET name='Coka Cola'; | |
-- boreal | |
RELATE beverage:tea->soldin->coffeeshop:boreal SET price=2.0; | |
RELATE beverage:latte->soldin->coffeeshop:boreal SET price=3.5; | |
RELATE beverage:coka_cola->soldin->coffeeshop:boreal SET price=2.5; | |
-- starbucks | |
RELATE beverage:tea->soldin->coffeeshop:starbucks SET price=3.5; | |
RELATE beverage:latte->soldin->coffeeshop:starbucks SET price=4.5; | |
RELATE beverage:caramel_macchiato->soldin->coffeeshop:starbucks SET price=8.5; | |
-- select prices of latte | |
SELECT name, {name: ->soldin->coffeeshop.name, price: ->soldin.price } AS shops FROM beverage:latte; | |
-- [ | |
-- { | |
-- "time":"369.625µs", | |
-- "status":"OK", | |
-- "result":[ | |
-- { | |
-- "name":"Latte" | |
-- "shops":{ | |
-- "name":["Boreal","StarBucks"], | |
-- "price":["3.5","4.5"] | |
-- }, | |
-- } | |
-- ] | |
-- } | |
-- ] | |
-- desired result | |
-- [ | |
-- { | |
-- "time":"369.625µs", | |
-- "status":"OK", | |
-- "result":[ | |
-- { | |
-- "name":"Latte" | |
-- "shops":[ | |
-- { "name": "Boreal","price": 3.5 }, | |
-- { "name": "StarBucks","price": 4.5 } | |
-- ], | |
-- } | |
-- ] | |
-- } | |
-- ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment