Update documentation content

This commit is contained in:
2026-03-15 05:32:05 +01:00
parent 7d10f030f3
commit c0b92596ec
30 changed files with 1840 additions and 29 deletions
+37
View File
@@ -0,0 +1,37 @@
---
title: API SQL Reference | Datasquirel docs
description: Execute raw SQL queries via the Datasquirel API
page_title: SQL API
page_description: Run raw MariaDB SQL queries against your databases using the Datasquirel API.
---
## Overview
The SQL API lets you execute any valid MariaDB SQL statement directly against your database and receive the result set as JSON. Use it when the standard CRUD endpoints don't cover your use case — complex JOINs, aggregations, subqueries, or DDL operations.
<div className="w-full grid grid-cols-1 gap-4 items-stretch">
<DocsCard
title="OPTIONS"
description="Execute a raw SQL query against your database."
href="/docs/api-reference/sql/options"
/>
</div>
## Quick Example
```javascript
import datasquirel from "@moduletrace/datasquirel";
const result = await datasquirel.api.sql({
key: process.env.DATASQUIREL_API_KEY,
params: {
query: "SELECT * FROM users WHERE is_active = 1 ORDER BY created_at DESC LIMIT 10",
},
});
console.log(result.payload);
```
## Authentication
A **Full Access** API key is required to run raw SQL queries. Read-only keys cannot use the SQL endpoint.
+81
View File
@@ -0,0 +1,81 @@
---
title: API SQL OPTIONS | Datasquirel docs
description: Execute a raw SQL query via the Datasquirel API
page_title: SQL OPTIONS
page_description: 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
```javascript
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
```javascript
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
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `key` | `string` | Yes | Full Access API key |
| `params.query` | `string` | Yes | The raw MariaDB SQL string to execute |
## REST API
```
POST /api/v1/sql
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```
**Body:**
```json
{
"query": "SELECT * FROM users WHERE is_active = 1 LIMIT 10"
}
```
## Response
```json
{
"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.