Turso icon

Turso

Execute operations on Turso database

Overview

This node allows executing SQL operations on a Turso database. It supports running arbitrary SQL queries, batch queries, and common CRUD (Create, Read, Update, Delete) operations on tables within the database. The node is useful for automating database interactions such as querying data, inserting new records, updating existing ones, deleting rows, and retrieving schema information.

Typical use cases include:

  • Running custom SQL queries to fetch or manipulate data.
  • Batch execution of multiple SQL statements in one go.
  • Inserting multiple rows into a table from incoming workflow data or manual input.
  • Selecting rows with optional filtering, ordering, and pagination.
  • Updating or deleting rows based on specified conditions.
  • Listing all tables or describing the schema of a specific table.

Example: You could use this node to query user data with a custom SELECT statement, insert new orders from an incoming webhook, or update product prices based on external inputs.

Properties

Name Meaning
Query The SQL query string to execute.
Query Parameters List of parameters to bind to the SQL query placeholders (?), in order of appearance.

These properties are specifically for the "Execute Query" operation.

Output

The output JSON structure depends on the executed query but generally includes:

  • columns: An array of column names returned by the query (if applicable).
  • rows: An array of result rows, each row being an array of values corresponding to the columns.
  • rowsAffected: Number of rows affected by the query (for INSERT, UPDATE, DELETE).
  • lastInsertRowid: The ID of the last inserted row (if applicable).

For example, after executing a SELECT query, the output will contain columns and rows representing the fetched data. For modification queries, it will provide rowsAffected and possibly lastInsertRowid.

The node does not output binary data.

Dependencies

  • Requires a Turso database connection configured with:
    • A valid database URL.
    • An API authentication token.

These credentials must be set up in n8n before using the node.

  • Uses the @libsql/client library internally to communicate with the Turso database.

Troubleshooting

Common Issues

  • Empty SQL query: The node throws an error if the SQL query string is empty or only whitespace.
  • Missing credentials: If the database URL or auth token is missing, the node will fail to connect.
  • Invalid table or column names: Errors occur if specified tables or columns do not exist.
  • Incorrect parameter count: When providing query parameters or values for insert/update, the count must match the expected number.
  • Missing WHERE clause for update/delete: For safety, these operations require a non-empty WHERE clause; otherwise, an error is thrown.
  • Item path not found: When using input items as data source, if the specified property path does not exist in the input JSON, an error occurs.

Error Messages and Resolutions

  • "SQL query cannot be empty": Provide a valid SQL query string.
  • "Database URL and auth token are required": Ensure credentials are properly configured.
  • "At least one column must be selected": Select columns when required by the operation.
  • "WHERE clause is required for update/delete operations for safety": Always specify a WHERE condition to avoid accidental full-table modifications.
  • "Values count (...) is not a multiple of columns count (...)": Check that the number of provided values matches the number of columns.
  • "Item path '...' not found in input data": Verify the input data structure and the specified property path.

Links and References


If you need details about other operations or additional properties, feel free to ask!

Discussion