Data Management

Working with data in Xano - The Basics

Summary

Welcome to Xano, a powerful no-code platform that simplifies the process of building and deploying backend services for web and mobile applications. In this guide, we'll explore the basics of working with data in Xano, covering essential concepts such as functions, variables, dot notation, filters, add-ons, and date and time manipulation. Let's dive in!

Functions

Functions are at the core of Xano's no-code API builder. They execute actions in a linear fashion, allowing you to perform various tasks such as database requests, data manipulation, caching, external API requests, and more.

To get started with functions, let's create a new API endpoint called "demo":

  1. Navigate to the no-code API builder.
  2. Click on "Start from scratch" and name your endpoint "demo."
  3. You'll see the "Function Stack" where you can add and arrange functions.

For this example, we'll add a function to fetch all records from a database table called "content." Here's how:

  1. Click on the "Database" section in the Function Stack.
  2. Select the "Query All Records" function.
  3. Choose the "content" table from the dropdown.
  4. Click "Save."

Now, when you run and debug this API endpoint, you'll receive all the records from the "content" table.

Variables

Variables act as containers for information in Xano. They can hold various data types such as text, objects, arrays, and more. The orange-colored items in the Function Stack are variables.

Let's create a new variable called "hello_world" with some static text:

  1. In the Function Stack, click on "Data Manipulation."
  2. Select the "Create Variable" function.
  3. Name the variable "hello_world."
  4. Enter the value "Hello there world!" in the text field.
  5. Click "Save."

Now, when you run and debug the API endpoint, the response will display the text you entered.

Dot Notation

Dot notation allows you to access and manipulate specific properties within an object or array. It's a powerful tool for extracting and transforming data stored in variables.

Let's say you want to retrieve only the name of the first item in the "content" table. Here's how you can achieve that using dot notation:

  1. In the Function Stack, update the "hello_world" variable by clicking on it.
  2. Replace the current value with `content1.0.name`.
  3. Click "Save."

When you run and debug the API endpoint, the response will display only the name of the first item in the "content" table.

Filters

Filters are another crucial concept in Xano. They allow you to transform the data you have in the Function Stack without executing additional actions. Filters can perform various operations such as text manipulation, math calculations, array conversions, and more.

Let's make the name of the first item in the "content" table uppercase using a filter:

  1. In the Function Stack, click on the "hello_world" variable.
  2. Click "Add Filter."
  3. Under the "Text" section, select the "To Upper" filter.
  4. Click "Update" and "Save."

Now, when you run and debug the API endpoint, the response will display the name of the first item in uppercase.

Add-ons

Add-ons enrich the data you're retrieving in your API request with related information. They are particularly useful when working with relational data stored across multiple tables.

Let's say the "content" table has a reference to a "users" table, where each content item is associated with a user. You can use an add-on to include the user information along with the content data:

  1. In the "Query All Records" function for the "content" table, click "Output."
  2. Click "Add-on" and then "Create a New Add-on."
  3. Select the "user" table as the add-on source.
  4. Choose the "Single Item" option (assuming each content item is associated with a single user).
  5. Click "Next" and then "Create."
  6. Optionally, you can rename the add-on by updating the "_user" field.
  7. Click "Save."

When you run and debug the API endpoint, the response will include the user information for each content item.

Date and Time

Xano stores all date and time values as Unix timestamps, which represent the number of milliseconds since January 1, 1970, 00:00:00 UTC. However, you can format these timestamps into human-readable formats using filters.

Let's create a new variable called "time_now" to display the current timestamp in a human-readable format:

  1. In the Function Stack, click on "Data Manipulation."
  2. Select the "Create Variable" function.
  3. Name the variable "time_now."
  4. Enter the value "now" in the text field (without quotes).
  5. Click "Add Filter."
  6. Under the "Timestamp" section, select the "Format Timestamp" filter.
  7. In the format field, enter "r" (without quotes) to display the timestamp in a human-readable format.
  8. Click "Update" and "Save."

When you run and debug the API endpoint, the response will display the current timestamp in a human-readable format.

You can also use relative timestamps (e.g., "last week," "2 weeks from now") or specific date formats by adjusting the format string in the "Format Timestamp" filter.

Conclusion

Working with data in Xano involves several key concepts: functions, variables, dot notation, filters, add-ons, and date and time manipulation. By mastering these concepts, you'll be able to build powerful backend services and transform data effectively without writing a single line of code.

Remember, this guide covers just the basics. Xano offers a wealth of advanced features and capabilities that you can explore further in the documentation. Happy building!

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free