Skip to main content
Please note that while in the visual builder, you can create addons directly from a database query statement. However, when working in XanoScript, you must manually define the addon before adding it to another database query.

Introduction

The addon primitive lets you define reusable database query components using XanoScript. Addons are specifically used alongside existing database queries to enrich the data with related data from other tables. Each addon corresponds to a database query that you can reuse across multiple APIs, functions, or other components — but expressed in code. Addons will typically:
  • Declare their name and description
  • Accept inputs for query parameters
  • Run a database query in the stack
  • Return the query results directly

Anatomy

Every XanoScript addon follows a predictable structure. Unlike other primitives, addons have a simplified structure focused on database queries. They contain input parameters, a database query stack, and optional settings. Here’s an example of a fully defined addon in XanoScript:
XanoScript
addon comment {
  description = "Gets all comments from a specific user"
  input {
    int user_id?
  }

  stack {
    db.query comment {
      search = $db.comment.user_id == $input.user_id
      return = {type: "list"}
    }
  }

  tags = ["database", "user data"]
}

Key Characteristics

Database Query Only: Addons can only contain database queries (db.query or db.get) in their stack. No other function types are allowed. No Response Block: Addons automatically return whatever the database query returns. The return value is determined by the return parameter:
  • {type: "list"} — Returns an array of records
  • {type: "single"} — Returns a single record
  • {type: "count"} — Returns the count of matching records
  • {type: "aggregate"} — Returns an aggregation of the records
Reusable Components: Perfect for creating reusable query logic that can be called from other functions or APIs.

Parameter Definition

ParameterRequiredDescription
descriptionnoOptional human-readable description of the addon.
Example: description = "Gets all comments from a specific user"
inputnoInput parameters for the database query.
Example: input { int user_id? }
stackDatabase query that will be executed. Must contain only db.query or db.get functions.
Example: stack { db.query comment { search = $db.comment.user_id == $input.user_id return = {type: "list"} } }
tagsnoA list of tags used to categorize and organize the addon in your workspace.
Example: tags = ["database", "user data"]

What’s Next

Now that you understand how to define addons in XanoScript, here are a few great next steps:

Explore the function reference

Learn about the database functions available in the stack to create more complex queries.
https://mintlify.s3.us-west-1.amazonaws.com/xano-997cb9ee/images/vscode.svg

Try it out in VS Code

Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.

Learn about APIs

Use addons in your API endpoints to create reusable database query components.
I