Register now: AI in Financial Services: Unlocking insights with Graph RAG webinar - April 24th

Done the tour!Done the tour!
Surrealist Placeholder
Surrealist Placeholder
Back to Courses

Done the tour!

Well done! You’ve reached the end of the tour. While thirty short pages is only enough to just scratch the surface, you are now familiar with many of the main features that SurrealDB has to offer.

Check out our other offerings to learn more:

  • SurrealDB Fundamentals, where you’ll build a simple ecommerce database, guided through both video and text and get a completion certificate at the end.
  • Aeon’s Surreal Renaissance, where you’ll immerse yourself in a fantasy book in which you follow the the main character in a medieval future that uses SurrealDB to rebuild the world of our 21st century.

And don’t forget to drop by any other parts of our community. The most active part of the community is Discord which is a great place to meet others using SurrealDB, share what you’re building or get advice, and talk directly with the SurrealDB employees (including the founders!) about just about anything.

And finally, here is the entire dataset for this tour - including the queries in the first few chapter for records that eventually got deleted.

Hope you enjoyed the course!

-- All queries used for the course, minus the quick ones just used to explain a concept -- Page 1: Nothing -- ** PAGES 2 to 6: fooling around and then deleting ** -- Only part that remains is the automatically generated -- DEFINE TABLE statements -- Page 2 CREATE place SET place_type = "library"; CREATE place:my_library; -- Page 3 CREATE place; CREATE ONLY place; -- Page 4 CREATE ONLY place:`ma_bibliothèque`; CREATE ONLY place:`良い図書館`; CREATE ONLY place:`𒂍𒁾𒁀𒀀`; CREATE ONLY `📚📚`:`🧑‍🎓💪💪💪`; -- Page 5 (CREATE place)[0]; (CREATE place).id; (CREATE place SET place_type = "library", num_books = 10000).{ place_type, num_books }; -- Page 6 CREATE some_record; DELETE some_record; DELETE place RETURN BEFORE; -- Page 7 CREATE place:surreal_library SET name = "Surreal Library", address = "2025 Statement Street, Riverdale", place_type = "library", floors = 8; -- Page 8: Nothing -- Page 9: Nothing -- Page 10: Nothing -- Page 11 CREATE town:riverdale SET name = "Riverdale"; UPDATE town SET population = 75000 WHERE name = "Riverdale"; -- Page 12 UPDATE town:riverdale SET libraries = [place:surreal_library]; -- Page 13 REMOVE TABLE some_record; -- Page 14: Nothing -- Page 15 DEFINE FIELD address ON place TYPE string; DEFINE FIELD name ON place TYPE string; DEFINE FIELD name ON town TYPE string; DEFINE FIELD population ON town TYPE int; DEFINE FIELD libraries ON town TYPE option<array<record<place>>>; -- Page 16 DEFINE FIELD place_type ON place TYPE "building" | "tower" | "store" | "school" | "park" | "library"; DEFINE FIELD OVERWRITE population ON town TYPE int ASSERT $value >= 0; -- Page 17 -- Experimenting, 'person' records deleted later INSERT INTO person [ { "name": "Sara Bellum", "age": 30 }, { "name": "Lydia Wyndham", "age": 25 }, { "name": "Samm Schwartz", "age": 45 } ]; -- Page 18 -- Experimenting, 'person' records deleted later FOR $person IN [ { age: 30, name: 'Sara Bellum' }, { age: 25, name: 'Lydia Wyndham' }, { age: 45, name: 'Samm Schwartz' } ] { CREATE person SET age = $person.age, name = $person.name }; DELETE person; -- Page 19: Nothing -- Page 20 FOR $person IN [ { age: 30, name: 'Sara Bellum' }, { age: 25, name: 'Lydia Wyndham' }, { age: 45, name: 'Samm Schwartz' } ] { LET $created = CREATE ONLY person SET age = $person.age, name = $person.name; RELATE $created->works_at->place:surreal_library; }; -- Page 21: Nothing -- Page 22: Nothing -- Page 23 DEFINE FIELD account_created ON TABLE customer_of VALUE time::now() READONLY; DEFINE FIELD last_updated ON TABLE customer_of VALUE time::now(); DEFINE FIELD customer_for ON TABLE customer_of VALUE <future> { time::now() - account_created }; FOR $data IN [ { age: 15, name: 'Archie Andrews' }, { age: 15, name: 'Veronica Lodge' }, { age: 15, name: 'Betty Cooper' }, { age: 15, name: 'Jughead Jones' }, { age: 15, name: 'Reggie Mantle' }, { age: 50, name: 'Hiram P. Lodge' }, { age: 55, name: 'Geraldine Grundy' }, { age: 65, name: 'Waldo Weatherbee' } ] { LET $person = CREATE ONLY person SET name = $data.name, age = $data.age; RELATE $person->customer_of->place:surreal_library; }; FOR $data IN [ { author: 'Charles Dickens', english_title: 'A Tale of Two Cities', language: 'en', published: "1859-11-26", title: 'A Tale of Two Cities' }, { author: "Antoine de Saint-Exupéry", english_title: "The Little Prince", language: "fr", published: "1943-04-15", title: "Le Petit Prince" }, { author: 'Paulo Coelho', english_title: 'The Alchemist', language: 'pt', published: "1988-03-01", title: 'O Alquimista' }, { author: 'J.K. Rowling', english_title: "Harry Potter and the Philosopher's Stone", language: 'en', published: "1997-06-26", title: "Harry Potter and the Philosopher's Stone" }, { author: 'Agatha Christie', english_title: 'And Then There Were None', language: 'en', published: "1939-11-06", title: 'And Then There Were None' }, { author: 'Cao Xueqin', english_title: 'Dream of the Red Chamber', language: 'zh', published: "1791-03-01", title: '紅樓夢' }, { author: 'J.R.R. Tolkien', english_title: 'The Hobbit', language: 'en', published: "1937-09-21", title: 'The Hobbit' }, { author: 'Lewis Carroll', english_title: "Alice's Adventures in Wonderland", language: 'en', published: "1865-07-04", title: "Alice's Adventures in Wonderland" } ] { -- Create the author for each book, return just the object LET $author = CREATE ONLY person SET name = $data.author; -- Create the book, cast 'published' field from string to datetime LET $book = CREATE ONLY book SET author = $data.author, english_title = $data.english_title, language = $data.language, published = <datetime>$data.published, title = $data.title; -- Connect the author to the book RELATE $author->wrote->$book; -- Give the book to the library with a few copies of each RELATE place:surreal_library->has->$book SET copies = rand::int(1, 10); }; -- Page 24 DEFINE FIELD author ON book TYPE string; DEFINE FIELD language ON book TYPE string; DEFINE FIELD title ON book TYPE string; DEFINE EVENT language_check ON book WHEN $event = "CREATE" THEN { IF $after.language = 'en' { UPDATE $after SET english_title = $after.title; } ELSE IF $after.language != 'en' AND $after.english_title IS NONE { THROW "Please enter an English title for " + <string>$after.title + " written in " + <string>$after.language; } }; CREATE book SET title = "The Shadow Rising", author = "Robert Jordan", language = 'en'; -- Page 25 DEFINE INDEX unique_address ON TABLE place FIELDS address UNIQUE; -- Page 26 DEFINE TABLE OVERWRITE works_at TYPE RELATION IN person OUT place; DEFINE TABLE OVERWRITE wrote TYPE RELATION IN person OUT book; DEFINE TABLE OVERWRITE has TYPE RELATION IN place OUT book; DEFINE TABLE OVERWRITE customer_of TYPE RELATION IN person OUT place; -- Page 27: Nothing -- Page 28 CREATE street:bowler_hat_alley SET name = "Bowler Hat Alley", connected_to = [street:index_avenue, street:rust_row]; CREATE street:graph_query_lane SET name = "Graph Query Lane", connected_to = [street:push_to_main_street, street:recursive_crossing, street:statement_street]; CREATE street:index_avenue SET name = "Index Avenue", connected_to = [place:event_junction, place:surreal_square, place:surrealdb_university, street:bowler_hat_alley,street:record_link_way, street:rust_row, street:statement_street]; CREATE street:push_to_main_street SET name = "Push to Main Street", connected_to = [street:graph_query_lane, street:record_link_way,place:vector_park]; CREATE street:transaction_trail SET name = "Transaction Trail", connected_to = [street:rust_row]; CREATE street:record_link_way SET name = "Record Link Way", connected_to = [place:surreal_square, place:surrealdb_university, place:vector_park, street:index_avenue,street:push_to_main_street, street:statement_street]; CREATE street:recursive_crossing SET name = "Recursive Crossing", connected_to = <future> { rand::enum([street:recursive_crossing, street:schema_boulevard, street:statement_street]) }; CREATE street:rust_row SET name = "Rust Row", connected_to = [place:idiom_tower, place:transaction_trail, street:bowler_hat_alley, street:index_avenue, street:schema_boulevard]; CREATE street:schema_boulevard SET name = "Schema Boulevard", connected_to = [place:access_court, street:rust_row, street:recursive_crossing]; CREATE street:statement_street SET name = "Statement Street", connected_to = [place:record_store, place:idiom_tower, street:index_avenue, street:record_link_way, street:recursive_crossing, street:graph_query_lane]; CREATE place:access_court SET address = "100 Schema Boulevard", name = "Access Court", place_type = "building", connected_to = [street:rust_row, street:schema_boulevard]; CREATE place:event_junction SET address = "50 Index Avenue", name = "Event Junction", place_type = "building", connected_to = [street:index_avenue, street:rust_row]; CREATE place:idiom_tower SET address = "100 Statement Street", name = "Idiom Tower", place_type = "tower", connected_to = [street:bowler_hat_alley, street:rust_row, street:schema_boulevard]; CREATE place:record_store SET address = "120 Statement Street", name = "Record Store", place_type = "store", connected_to = [street:record_link_way, street:statement_street]; CREATE place:surreal_square SET address = "100 Index Avenue", name = "Surreal Square", place_type = "park", connected_to = [place:surrealdb_university, street:index_avenue, street:record_link_way]; CREATE place:surrealdb_university SET address = "150 Index Avenue", name = "SurrealDB University", place_type = "school", connected_to = [place:surreal_square, street:index_avenue, street:record_link_way]; CREATE place:transaction_trail SET address = "60 Rust Row", name = "Transaction Trail", place_type = "park", connected_to = [street:rust_row]; CREATE place:vector_park SET address = "10 Push to Main Street", name = "Vector Park", place_type = "park", connected_to = [street:push_to_main_street, street:record_link_way]; UPDATE town:riverdale SET streets = SELECT VALUE id FROM street, buildings = [place:event_junction, place:access_court, place:record_store, place:idiom_tower], schools = [place:surrealdb_university];