LibSQL Node icon

LibSQL Node

A community node to interact with LibSQL databases

Overview

This node allows users to interact with LibSQL databases by executing SQL queries of various types. It supports common database operations such as creating tables, inserting rows, selecting data, updating rows, and deleting rows. The node is useful in scenarios where you want to integrate SQL database operations directly into your n8n workflows without writing custom code or managing database connections manually.

Practical examples include:

  • Running a SELECT query to fetch user data based on dynamic input parameters.
  • Inserting new records into a table after processing some data.
  • Updating or deleting records conditionally within an automated workflow.
  • Creating tables dynamically during setup or migration processes.

Properties

Name Meaning
Query Type The type of SQL query to execute. Options: CREATE (create a table), DELETE (delete rows), INSERT (insert rows), SELECT (select rows, supports multiple queries), UPDATE (update rows).
Query The actual SQL query string to execute. Supports parameter substitution using $parameterName syntax, where values are taken from the incoming JSON data fields.

Output

The node outputs an array of items corresponding to each input item processed:

  • For SELECT queries:

    • Outputs one item per row returned by the query, each containing the row data in the json field.
    • If no rows are found, outputs a single item with { result: "No rows found" }.
  • For INSERT, UPDATE, DELETE, and CREATE queries:

    • Outputs a single item with a JSON object containing:
      • success: boolean indicating if the operation succeeded.
      • changes: number of rows affected (if applicable).
      • lastInsertRowid: ID of the last inserted row (if applicable).
      • query: the executed query string.
      • queryType: the type of query executed.
  • For other query types:

    • Outputs the raw result under result, along with the executed query and query type.

The output items maintain pairing with their respective input items for traceability.

Dependencies

  • Requires a valid API key credential for authenticating with the LibSQL service.
  • Needs the LibSQL client library (@libsql/client) to communicate with the database.
  • The node expects configuration of credentials that provide:
    • An authentication token.
    • The database URL endpoint.

Troubleshooting

  • Empty Query Error: If the "Query" property is empty or only whitespace, the node throws an error stating "Query cannot be empty". Ensure the query string is properly set.
  • Parameter Substitution Issues: The node replaces placeholders like $key with values from the input JSON. If a placeholder does not match any input field, it remains unchanged, which may cause SQL errors. Verify that all placeholders correspond to existing input data fields.
  • Database Connection Errors: Failures to connect to the LibSQL database usually indicate incorrect credentials or network issues. Check the API token and database URL configuration.
  • Query Execution Errors: Syntax errors or invalid SQL statements will cause the node to throw errors. Review the query syntax carefully.
  • Continue On Fail Behavior: If enabled, the node will continue processing subsequent items even if one fails, returning error details in the output JSON.

Links and References

Discussion