In this section, you will explore writing SurrealQL queries using Surrealist, the official query editor for SurrealDB. Surrealist is a powerful tool that allows you to write, execute, and visualize SurrealQL queries in real-time.
The Surrealist query editor provides a rich set of features, including syntax highlighting, query validation, and query execution. You can also view the query results in a tabular format, making it easy to analyze and visualize the data.
To get started with SurrealQL in Surrealist, go to the Surrealist Query Editor and start writing your SurrealQL queries. You can use the query editor to write queries, execute them, and view the results in real-time.
Within the connection list you will find a special connection called Sandbox, which is always available and allows you to test and experiment without storing data persistently. The Sandbox is useful for learning SurrealQL, testing queries, and more. This connection is designed for simple testing and not for evaluating performance, as it is limited to a single thread within the browser’s WebAssembly engine.
In order to interact with a SurrealDB database by any other means you must first create a connection. Connections store the details required to connect to a database, such as the endpoint, namespace, database, and authentication details. When you select an active connection in Surrealist, you will connect to the database and be able to interact with it using the available interface views.
After opening a connection, you can switch to another connection at any time by pressing the connection name in the top left of the interface. This will open the connection list allowing you to switch to another connection, or create a new one.
You can also create a new custom connection which will allow you to connect to a remote or local SurrealDB instance.
If you are using a connection (local or remote), you need to set the namespace and database for the connection before you can start writing queries.
For example, you can set both the namespace to main and the database to main. This will set the namespace and database for the current connection.
Once you have a connection open, you can use the SurrealQL query editor to create some data. For example, you can create a new record in the person table.
CREATE person SET name = "John", age = 30;
In the query editor, you can use syntax highlighting, code completion, and validation to help you write your queries more efficiently. To execute a query, press the run query button at the bottom of the query editor.
To learn more about SurrealQL and how to write queries using Surrealist, check out the Surrealist documentation.