Repository navigation
SurrealQL Conventions
jamster edited this page Nov 22, 2026
·
1 revision
These conventions apply to all .surql files. Those files are used when there are a large number of queries to run, such as initial.surql.
- Params:
SCREAMING_SNAKE_CASE, for example$MAX_USERNAME_BYTES - Tables and fields:
snake_case, for exampleuser_settings
- Open with a reference block of
--comments if the file defines params or constants that need explaining, such as bytes size tables. - Group related definitions under a section banner:
-- =========================================================
-- SECTION NAME
-- =========================================================- Within a section, order each table block as:
DEFINE TABLE, then fields, then indexes. - Leave a blank line between each
DEFINE TABLEandDEFINTE INDEX. Leave two black lines between each table block. - Use
IF NOT EXISTSon all definitions unlessOVERWRITEis explicitly needed.
-- Users
DEFINE TABLE IF NOT EXISTS users SCHEMAFULL;
DEFINE FIELD IF NOT EXISTS username ON TABLE users TYPE string
ASSERT fn::bytes_within($value, $MIN_DEFAULT_BYTES, $MAX_USERNAME_BYTES);
DEFINE FIELD IF NOT EXISTS email ON TABLE users TYPE string
ASSERT fn::bytes_within($value, $MIN_DEFAULT_BYTES, $MAX_EMAIL_BYTES);
DEFINE INDEX IF NOT EXISTS idx_username ON TABLE users COLUMNS username UNIQUE;
DEFINE INDEX IF NOT EXISTS idx_email ON TABLE users COLUMNS email UNIQUE;