Overview
This node provides an interface to a Turso database, allowing users to execute SQL queries directly from n8n workflows. It is designed as an AI tool that can be referenced by an AI Agent to perform database operations such as querying, inserting, updating, or deleting data. This node is particularly useful when you want to integrate dynamic database interactions into automated workflows or AI-driven processes.
Common scenarios:
- Running custom SQL queries on a Turso database to fetch or manipulate data.
- Integrating database results into downstream workflow steps for further processing.
- Allowing an AI Agent to interact with a database by providing schema context and query capabilities.
- Limiting the number of rows returned to avoid overwhelming subsequent nodes.
Practical example:
You might use this node to query customer records based on certain criteria, then pass those results to another node for sending personalized emails or generating reports.
Properties
| Name | Meaning |
|---|---|
| Tool Name | The name by which the AI Agent will refer to this node/tool. |
| Description | A detailed description of what this tool does, helping the AI understand when to use it. |
| Schema Information | Additional textual information about the database schema (tables, columns) to assist the AI in querying. |
| Max Rows | Maximum number of rows to return from any executed query, limiting output size. |
| Input Schema | JSON schema defining the expected input structure for the tool, including the SQL query and optional parameters. |
Output
The node outputs a JSON object with the following structure:
success(boolean): Indicates if the query was executed successfully.columns(array of strings): Names of the columns returned by the query.rows(array of arrays): The actual data rows returned, limited by the "Max Rows" property.rowCount(number): Number of rows included in the output.rowsAffected(number): Number of rows affected by the query (for insert/update/delete).lastInsertRowid(string, optional): ID of the last inserted row if applicable.message(string): Informational message, e.g., noting if results were truncated due to row limits or confirming successful execution.
If the query returns no results, the output indicates success but with empty rows and columns.
The node does not output binary data.
Dependencies
- Requires a Turso database connection with:
- A valid database URL.
- An authentication token.
- Uses the
@libsql/clientlibrary to connect and execute SQL queries against the Turso database. - Requires appropriate credentials configured in n8n to authenticate with the Turso database.
Troubleshooting
- Missing Credentials: If the database URL or auth token is missing, the node throws an error indicating these are required.
- Missing Query: If the input JSON does not contain a
querystring, the node throws an error stating that the SQL query is required. - Database Errors: Errors from the database client are caught and rethrown with messages prefixed by "Database error:" along with the error code if available.
- General Execution Errors: Other errors during query execution are caught and reported with a generic message including the original error message if present.
Tips:
- Ensure your SQL query syntax is correct and compatible with the Turso database.
- Verify that the authentication token and database URL are correctly set in the node credentials.
- Use the "Max Rows" property to limit large result sets and prevent performance issues.
- Provide accurate schema information to help AI Agents generate better queries.