SQL API
POST /api/sql (superusers)
Runs one SQL statement on the app's main database and answers its result. Reads answer at most 1,000 rows.
| Body | |
|---|---|
query |
the statement |
curl -X POST http://127.0.0.1:8090/api/sql -H "Authorization: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": "SELECT author, COUNT(*) AS posts FROM posts GROUP BY author"}'
{
"execTime": 1,
"affectedRows": 0,
"columns": [
{ "name": "author", "type": "TEXT", "nullable": true },
{ "name": "posts", "type": "", "nullable": true }
],
"rows": [["0slkeutr0bxpw3v", "1"]]
}
type is the column's declared type, empty for an expression like COUNT(*); values come back as SQLite gives
them, so an expression's number may arrive as a string.
It runs as written, past rules and hooks, so a write here skips validation: use it for reading and repairs, and the Records API for normal writes.
Next
- Records: queries from your own code, with bound parameters.
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.