GET

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

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

const result = await datasquirel.crud.get({
    dbName: "my_database",
    tableName: "users",
    targetId: 42,
    apiKey: process.env.DATASQUIREL_API_KEY,
});

Filtered and Paginated Query

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

ParameterTypeRequiredDescription
dbNamestringYesThe database slug to query
tableNamestringYesThe table to read from
apiKeystringNoAPI key. Falls back to the DATASQUIREL_API_KEY environment variable
targetIdstring | numberNoFetch a single record by its id
queryobjectNoFilter, pagination, and ordering options (see below)

Query Options

OptionTypeDescription
limitnumberMaximum number of records to return
pagenumberPage number for pagination (1-based)
offsetnumberNumber of records to skip
order{ field, strategy }Sort by a field — strategy is "ASC" or "DESC"
selectFieldsstring[]Only return these fields
omitFieldsstring[]Exclude these fields from the result
queryobjectField-level filters — each key is a field name with a value and equality
fullTextSearchobjectFull-text search across specified fields
joinarrayJOIN 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

{
    "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.