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