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
+93
View File
@@ -0,0 +1,93 @@
---
title: API CRUD DELETE | Datasquirel docs
description: Delete a record from a Datasquirel table via the API
page_title: DELETE
page_description: Delete one or more records from a table using the Datasquirel REST API or npm package.
---
## Overview
Use the DELETE endpoint to remove records from a table. You can delete by a specific record ID or by matching field values.
## npm Package
### Delete by ID
```javascript
import datasquirel from "@moduletrace/datasquirel";
const result = await datasquirel.crud.delete({
dbName: "my_database",
tableName: "users",
targetID: 42,
apiKey: process.env.DATASQUIREL_API_KEY,
});
```
### Delete by Field Value
```javascript
const result = await datasquirel.crud.delete({
dbName: "my_database",
tableName: "sessions",
deleteSpec: {
deleteKeyValues: [
{ key: "user_id", value: 42, operator: "=" },
],
},
apiKey: process.env.DATASQUIREL_API_KEY,
});
```
## Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dbName` | `string` | Yes | The database slug |
| `tableName` | `string` | Yes | The table to delete from |
| `targetID` | `string \| number` | No | The `id` of the record to delete. Either `targetID` or `deleteSpec` is required |
| `deleteSpec` | `object` | No | Field-value conditions for deletion (see below) |
| `apiKey` | `string` | No | API key. Falls back to `DATASQUIREL_API_KEY` environment variable |
### deleteSpec.deleteKeyValues
An array of conditions. Each condition has:
| Field | Type | Description |
|-------|------|-------------|
| `key` | `string` | The field name to match |
| `value` | `string \| number \| null` | The value to match against |
| `operator` | `string` | Comparison operator — `"="`, `"!="`, `">"`, `"<"`, etc. Defaults to `"="` |
## REST API
```
DELETE /api/v1/crud/{dbName}/{tableName}/{id}
DELETE /api/v1/crud/{dbName}/{tableName}
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```
**Body (when deleting by field value):**
```json
{
"deleteKeyValues": [
{ "key": "user_id", "value": 42, "operator": "=" }
]
}
```
## Response
```json
{
"success": true,
"payload": 1
}
```
A successful response returns `success: true` and `payload` with the number of deleted rows.
+104
View File
@@ -0,0 +1,104 @@
---
title: API CRUD GET | Datasquirel docs
description: Fetch records from a Datasquirel table via the API
page_title: GET
page_description: Read one or more records from a table using the Datasquirel REST API or npm package.
---
## Overview
Use the GET endpoint to fetch records from any table in your database. You can retrieve all records, a single record by ID, or a filtered and paginated subset.
## npm Package
```javascript
import datasquirel from "@moduletrace/datasquirel";
const result = await datasquirel.crud.get({
dbName: "my_database",
tableName: "users",
apiKey: process.env.DATASQUIREL_API_KEY,
});
// result.payload contains the array of records
console.log(result.payload);
```
### Get a Single Record by ID
```javascript
const result = await datasquirel.crud.get({
dbName: "my_database",
tableName: "users",
targetId: 42,
apiKey: process.env.DATASQUIREL_API_KEY,
});
```
### Filtered and Paginated Query
```javascript
const result = await datasquirel.crud.get({
dbName: "my_database",
tableName: "posts",
apiKey: process.env.DATASQUIREL_API_KEY,
query: {
limit: 10,
page: 1,
order: { field: "created_at", strategy: "DESC" },
query: {
is_published: { value: 1, equality: "=" },
},
},
});
```
## Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dbName` | `string` | Yes | The database slug to query |
| `tableName` | `string` | Yes | The table to read from |
| `apiKey` | `string` | No | API key. Falls back to the `DATASQUIREL_API_KEY` environment variable |
| `targetId` | `string \| number` | No | Fetch a single record by its `id` |
| `query` | `object` | No | Filter, pagination, and ordering options (see below) |
### Query Options
| Option | Type | Description |
|--------|------|-------------|
| `limit` | `number` | Maximum number of records to return |
| `page` | `number` | Page number for pagination (1-based) |
| `offset` | `number` | Number of records to skip |
| `order` | `{ field, strategy }` | Sort by a field — `strategy` is `"ASC"` or `"DESC"` |
| `selectFields` | `string[]` | Only return these fields |
| `omitFields` | `string[]` | Exclude these fields from the result |
| `query` | `object` | Field-level filters — each key is a field name with a `value` and `equality` |
| `fullTextSearch` | `object` | Full-text search across specified fields |
| `join` | `array` | JOIN conditions against other tables |
## REST API
```
GET /api/v1/crud/{dbName}/{tableName}
GET /api/v1/crud/{dbName}/{tableName}/{id}
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
```
## Response
```json
{
"success": true,
"payload": [
{ "id": 1, "name": "Alice", "email": "[email protected]" },
{ "id": 2, "name": "Bob", "email": "[email protected]" }
]
}
```
A successful response has `success: true` and a `payload` array. A single-record fetch (by `targetId`) returns `payload` as an object.
@@ -0,0 +1,46 @@
---
title: API CRUD OPTIONS | Datasquirel docs
description: Inspect available CRUD operations for a table
page_title: OPTIONS
page_description: Retrieve metadata about the CRUD operations available for a table.
---
## Overview
The OPTIONS endpoint returns metadata about the available operations for a given table — useful for dynamically discovering what fields and actions are supported.
## REST API
```
OPTIONS /api/v1/crud/{dbName}/{tableName}
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
```
## Response
The response includes information about the table schema and the HTTP methods supported for that table.
```json
{
"success": true,
"payload": {
"methods": ["GET", "POST", "PUT", "DELETE"],
"schema": [
{ "name": "id", "type": "int", "required": true },
{ "name": "name", "type": "varchar(255)", "required": true },
{ "name": "email", "type": "varchar(255)", "required": false }
]
}
}
```
## Related
- [GET](/docs/api-reference/crud/get) — read records
- [POST](/docs/api-reference/crud/post) — create records
- [PUT](/docs/api-reference/crud/put) — update records
- [DELETE](/docs/api-reference/crud/delete) — delete records
+88
View File
@@ -0,0 +1,88 @@
---
title: API CRUD POST | Datasquirel docs
description: Create a new record in a Datasquirel table via the API
page_title: POST
page_description: Insert a new record into a table using the Datasquirel REST API or npm package.
---
## Overview
Use the POST endpoint to insert a new record into a table. Provide the data as a plain object — the keys must match your table's field names.
## npm Package
```javascript
import datasquirel from "@moduletrace/datasquirel";
const result = await datasquirel.crud.insert({
dbName: "my_database",
tableName: "users",
body: {
name: "Alice",
email: "[email protected]",
is_active: 1,
},
apiKey: process.env.DATASQUIREL_API_KEY,
});
// result.payload is the inserted record's ID
console.log(result.payload);
```
### Insert Multiple Records (Batch)
You can insert multiple records in a single request by passing an array in a `batchData` field:
```javascript
const result = await datasquirel.crud.insert({
dbName: "my_database",
tableName: "tags",
body: { batchData: [
{ name: "javascript" },
{ name: "typescript" },
{ name: "sql" },
]},
apiKey: process.env.DATASQUIREL_API_KEY,
});
```
## Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dbName` | `string` | Yes | The database slug |
| `tableName` | `string` | Yes | The table to insert into |
| `body` | `object` | Yes | The record to insert. Keys must match field names |
| `apiKey` | `string` | No | API key. Falls back to `DATASQUIREL_API_KEY` environment variable |
## REST API
```
POST /api/v1/crud/{dbName}/{tableName}
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```
**Body:**
```json
{
"name": "Alice",
"email": "[email protected]",
"is_active": 1
}
```
## Response
```json
{
"success": true,
"payload": 7
}
```
A successful response returns `success: true` and `payload` containing the `insertId` (the auto-incremented `id` of the new record).
+68
View File
@@ -0,0 +1,68 @@
---
title: API CRUD PUT | Datasquirel docs
description: Update an existing record in a Datasquirel table via the API
page_title: PUT
page_description: Update an existing record in a table using the Datasquirel REST API or npm package.
---
## Overview
Use the PUT endpoint to update an existing record. You must provide the `id` of the record you want to update, along with the fields you want to change. Only the fields you include in the body are updated — other fields are left unchanged.
## npm Package
```javascript
import datasquirel from "@moduletrace/datasquirel";
const result = await datasquirel.crud.update({
dbName: "my_database",
tableName: "users",
targetID: 42,
body: {
name: "Alice Updated",
is_active: 0,
},
apiKey: process.env.DATASQUIREL_API_KEY,
});
```
## Parameters
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `dbName` | `string` | Yes | The database slug |
| `tableName` | `string` | Yes | The table to update |
| `targetID` | `string \| number` | Yes | The `id` of the record to update |
| `body` | `object` | Yes | Fields to update. Keys must match field names |
| `apiKey` | `string` | No | API key. Falls back to `DATASQUIREL_API_KEY` environment variable |
## REST API
```
PUT /api/v1/crud/{dbName}/{tableName}/{id}
```
**Headers:**
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```
**Body:**
```json
{
"name": "Alice Updated",
"is_active": 0
}
```
## Response
```json
{
"success": true,
"payload": 1
}
```
A successful response returns `success: true` and `payload` with the number of affected rows (typically `1`).