SQL Compatibility Layer
Write familiar SQL queries that are automatically translated to SDBQL. Perfect for developers transitioning from traditional databases.
Overview
SoliDB provides a SQL compatibility layer that translates standard SQL syntax into SDBQL. This allows you to use familiar SQL statements while leveraging SoliDB's document-oriented storage.
✓ Supported Statements
- • SELECT with columns and *
- • INSERT INTO ... VALUES
- • UPDATE ... SET ... WHERE
- • DELETE FROM ... WHERE
✓ Supported Clauses
- • WHERE with conditions
- • ORDER BY (ASC/DESC)
- • LIMIT / OFFSET
- • GROUP BY / HAVING
SELECT Queries
Basic SELECT
SQL
SELECT * FROM users
SDBQL
FOR doc IN users
RETURN doc
Selecting Columns
SQL
SELECT name, age FROM users
SDBQL
FOR doc IN users
RETURN { name: doc.name, age: doc.age }
WHERE Clause
SQL
SELECT * FROM users
WHERE age > 18 AND status = 'active'
SDBQL
FOR doc IN users
FILTER doc.age > 18 AND doc.status == "active"
RETURN doc
ORDER BY, LIMIT, OFFSET
SQL
SELECT * FROM users
ORDER BY name DESC
LIMIT 10 OFFSET 20
SDBQL
FOR doc IN users
SORT doc.name DESC
LIMIT 20, 10
RETURN doc
JOIN Queries NEW
Join tables together to combine related data. JOINs are translated to nested FOR loops in SDBQL.
JOIN
Inner Join
LEFT JOIN
Left Outer Join
RIGHT JOIN
Right Outer Join
Basic JOIN
SQL
SELECT u.name, o.total
FROM users u
JOIN orders o ON o.user_id = u._key
SDBQL
FOR u IN users
FOR o IN orders
FILTER o.user_id == u._key
RETURN { name: u.name, total: o.total }
JOIN with SELECT *
SQL
SELECT * FROM users
INNER JOIN orders ON orders.user_id = users._key
SDBQL
FOR doc IN users
FOR j0 IN orders
FILTER orders.user_id == doc._key
RETURN MERGE(doc, j0)
Multiple JOINs
SQL
SELECT u.name, o.total, p.title
FROM users u
JOIN orders o ON o.user_id = u._key
JOIN products p ON p._key = o.product_id
SDBQL
FOR u IN users
FOR o IN orders
FILTER o.user_id == u._key
FOR p IN products
FILTER p._key == o.product_id
RETURN { name: u.name, total: o.total, title: p.title }
LEFT JOIN
SQL
SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON o.user_id = u._key
SDBQL
FOR u IN users
FOR o IN orders
FILTER o.user_id == u._key
RETURN { name: u.name, total: o.total }
RIGHT JOIN
SQL
SELECT o.total, p.name
FROM orders o
RIGHT JOIN products p ON p._key = o.product_id
SDBQL
FOR o IN orders
FOR p IN products
FILTER p._key == o.product_id
RETURN { total: o.total, name: p.name }
INSERT Statements
SQL
INSERT INTO users (name, age, email)
VALUES ('Alice', 30, '[email protected]')
SDBQL
INSERT {
name: "Alice",
age: 30,
email: "[email protected]"
} INTO users
RETURN NEW
UPDATE Statements
SQL
UPDATE users
SET age = 31, status = 'verified'
WHERE name = 'Alice'
SDBQL
FOR doc IN users
FILTER doc.name == "Alice"
UPDATE doc WITH {
age: 31,
status: "verified"
} IN users
RETURN NEW
DELETE Statements
SQL
DELETE FROM users WHERE age < 18
SDBQL
FOR doc IN users
FILTER doc.age < 18
REMOVE doc IN users
RETURN OLD
Supported Operators
| SQL Operator | SDBQL Equivalent | Example |
|---|---|---|
= |
== |
name = 'Alice' |
!= / <> |
!= |
status != 'deleted' |
LIKE |
LIKE |
name LIKE 'A%' |
IN (...) |
IN [...] |
status IN ('active', 'pending') |
BETWEEN |
>= AND <= |
age BETWEEN 18 AND 65 |
IS NULL |
== null |
email IS NULL |
IS NOT NULL |
!= null |
email IS NOT NULL |
AND / OR |
AND / OR |
age > 18 AND active = true |
API Endpoints
Execute SQL Query
POST /_api/database/{db}/sql
{
"query": "SELECT * FROM users WHERE age > 18",
"bind_vars": {},
"dry_run": false
}
Set dry_run: true to preview the SDBQL without executing.
Translate SQL to SDBQL
POST /_api/sql/translate
{
"query": "SELECT name, age FROM users ORDER BY name LIMIT 10"
}
Returns the translated SDBQL query without executing it.
Example: cURL
curl -X POST http://localhost:7777/_api/database/mydb/sql \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT * FROM users WHERE age > 18 ORDER BY name LIMIT 10"
}'
Dashboard SQL Mode
The Query page in the SoliDB dashboard supports both SDBQL and SQL modes. Use the toggle switch in the header to switch between modes.
How to Use SQL Mode
- Navigate to Dashboard → Query
- Toggle the switch from SDBQL to SQL
- Write your SQL query in the editor
- Watch the live SDBQL translation appear below the editor
- Click Run Query to execute
Live Translation
See your SQL translated to SDBQL in real-time as you type.
Validation
Status indicator shows whether your SQL syntax is valid.