db-anub

n8n node for Cloudflare D1 Manager Worker API - Manage D1 databases with select, insert, update, delete, and more

Package Information

Released: 2 mo ago
Downloads: 0 weeklyΒ /Β 0 monthly
Latest Version: 0.2.4

Documentation

n8n-nodes-db-anub

npm version
License: MIT

An n8n community node for interacting with Cloudflare D1 databases via the D1 Manager Worker API.

πŸš€ Features

  • Full CRUD Operations: Select, Insert, Update, Delete records
  • Advanced Queries: JOINs, WHERE conditions, ORDER BY, GROUP BY, LIMIT/OFFSET
  • Aggregate Functions: Count and Exists operations
  • Raw SQL: Execute custom SQL queries
  • Batch Operations: Execute multiple statements atomically
  • Database Discovery: List all configured D1 database bindings
  • Secure Authentication: API key-based authentication
  • AI-Ready: Usable as a tool in n8n AI workflows

πŸ“¦ Installation

Via n8n Community Nodes (Recommended)

  1. Go to Settings > Community Nodes
  2. Select Install
  3. Enter n8n-nodes-db-anub
  4. Select Install

Via npm

npm install n8n-nodes-db-anub

Manual Installation

# Clone or download this repository
cd n8n-nodes-db-anub
npm install
npm run build
npm link

# In your n8n custom directory
mkdir -p ~/.n8n/custom
cd ~/.n8n/custom
npm init -y
npm link n8n-nodes-db-anub

πŸ”§ Prerequisites

  1. D1 Manager Worker deployed to Cloudflare Workers
  2. API Key configured in your worker
  3. D1 Database bindings configured in your worker

See the D1 Manager Worker API documentation for setup instructions.

πŸ” Credentials Setup

  1. In n8n, go to Credentials > Add Credential
  2. Search for D1 Manager API
  3. Enter:
    • Base URL: Your worker URL (e.g., https://your-worker.your-subdomain.workers.dev)
    • API Key: Your API key for authentication
  4. Click Save

πŸ“– Operations

Resource: Record

Perform CRUD operations on database tables.

Select

Retrieve records from a table with optional filtering, ordering, and pagination.

Field Type Description
Database Select D1 database binding (dropdown list - auto-populated from your worker)
Table String Target table name
Columns String Comma-separated columns (default: *)
Distinct Boolean Return distinct rows only
Where Conditions JSON WHERE condition tree
Joins JSON Array of JOIN clauses
Order By JSON Array of order clauses
Group By JSON Array of columns to group by
Limit Number Maximum rows to return
Offset Number Rows to skip

Example Where Conditions:

{
  "column": "status",
  "op": "=",
  "value": "active"
}

Nested conditions:

{
  "and": [
    { "column": "status", "op": "=", "value": "active" },
    {
      "or": [
        { "column": "score", "op": ">", "value": 100 },
        { "column": "score", "op": "is null" }
      ]
    }
  ]
}

Example Joins:

[
  { "type": "inner", "table": "orders", "on": "users.id = orders.user_id" }
]

Example Order By:

[
  { "column": "created_at", "dir": "desc" },
  { "column": "name", "dir": "asc" }
]

Insert

Insert one or multiple records into a table.

Field Type Description
Database Select D1 database binding (dropdown list)
Table String Target table name
Data Fields Add column name and value pairs

Data Field:

  • Click "Add Column" to add a new column
  • Enter the column name and its value
  • Add as many columns as needed

Example:

Column Name Value
name Alice
email alice@example.com
active true

Update

Update records in a table.

Field Type Description
Database Select D1 database binding (dropdown list)
Table String Target table name
Data Fields Column values to update (add column/value pairs)
Where Conditions JSON WHERE condition tree

Delete

Delete records from a table.

Field Type Description
Database String D1 database binding name
Table String Target table name
Where Conditions JSON WHERE condition tree

Count

Count records in a table.

Field Type Description
Database Select D1 database binding (dropdown list)
Table String Target table name
Where Conditions JSON WHERE condition tree (optional)

Exists

Check if records exist in a table.

Field Type Description
Database Select D1 database binding (dropdown list)
Table String Target table name
Where Conditions JSON WHERE condition tree

Resource: Raw SQL

Execute custom SQL queries.

Field Type Description
Database Select D1 database binding (dropdown list)
SQL Query String Raw SQL to execute

Example:

CREATE TABLE IF NOT EXISTS users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  email TEXT UNIQUE,
  created_at TEXT DEFAULT CURRENT_TIMESTAMP
)

Resource: Batch

Execute multiple statements atomically in a single transaction.

Field Type Description
Database Select D1 database binding (dropdown list)
Statements JSON Array of action objects

Example:

[
  {
    "action": "insert",
    "table": "orders",
    "data": { "user_id": 1, "total": 99.99, "status": "pending" }
  },
  {
    "action": "update",
    "table": "users",
    "data": { "order_count": 5 },
    "where": { "column": "id", "op": "=", "value": 1 }
  }
]

Resource: Database

List all configured D1 database bindings.

πŸ“€ Response Format

All responses follow this structure:

Success:

{
  "success": true,
  "data": { ... },
  "meta": {
    "rows_read": 5,
    "rows_written": 0,
    "duration_ms": 12
  }
}

Error:

{
  "success": false,
  "error": {
    "message": "Human-readable description",
    "code": "MACHINE_READABLE_CODE"
  }
}

πŸ”’ Supported WHERE Operators

Operator Description
=, !=, <> Equality
<, <=, >, >= Comparison
like, not like Pattern matching
glob SQLite GLOB
regex, not regex, regexp, not regexp Regular expression
is arabic, not arabic Arabic character range [\u0600-\u06FF]
in, not in Set membership
between Range
is null, is not null Null checks

Arabic & Regex Filter Example:

{
  "where": {
    "and": [
      { "column": "ar", "op": "not arabic" },
      { "column": "title", "op": "regex", "value": "[\\u0600-\\u06FF]" }
    ]
  }
}

πŸ› οΈ Development

# Install dependencies
npm install

# Build the node
npm run build

# Development mode with watch
npm run dev

# Lint code
npm run lint
npm run lint:fix

πŸ“ License

MIT

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“š Related

❓ Support

If you encounter any issues or have questions, please open an issue on GitHub.

Discussion