SQL OPTIONS

Execute any valid MariaDB SQL statement and receive results as JSON.

Overview

The SQL OPTIONS endpoint accepts any valid MariaDB SQL string and executes it against your database. Results are returned as a JSON array.

npm Package

import datasquirel from "@moduletrace/datasquirel";

const result = await datasquirel.api.sql({
    key: process.env.DATASQUIREL_API_KEY,
    params: {
        query: "SELECT posts.id, posts.title, users.name AS author FROM posts JOIN users ON posts.user_id = users.id WHERE posts.is_published = 1 ORDER BY posts.created_at DESC LIMIT 20",
    },
});

console.log(result.payload);

Aggregation Query

const result = await datasquirel.api.sql({
    key: process.env.DATASQUIREL_API_KEY,
    params: {
        query: "SELECT category, COUNT(*) AS total FROM posts GROUP BY category ORDER BY total DESC",
    },
});

Parameters

ParameterTypeRequiredDescription
keystringYesFull Access API key
params.querystringYesThe raw MariaDB SQL string to execute

REST API

POST /api/v1/sql

Headers:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Body:

{
    "query": "SELECT * FROM users WHERE is_active = 1 LIMIT 10"
}

Response

{
    "success": true,
    "payload": [
        { "id": 1, "name": "Alice", "email": "[email protected]" },
        { "id": 2, "name": "Bob", "email": "[email protected]" }
    ]
}

Notes

  • A Full Access API key is required.
  • All valid MariaDB statements are supported: SELECT, INSERT, UPDATE, DELETE, ALTER, CREATE, DROP, and more.
  • Be careful with DDL statements (ALTER, DROP) — they modify the table structure and cannot be undone.
  • Parameterized queries are not supported through this endpoint — sanitize user input before embedding it in a SQL string.