Overview

This guide will show you how to get started with Sequin. We’ll walk through the full life cycle of an integration: setting up a new sync, reading and writing data, changing your schema, and moving your sync from development to production.

In the next several minutes, you’ll build an integration with Airtable. You’ll be able to build the integration using just SQL, and without needing to consider the underlying API’s limitations or rate limits.

For this example, imagine your application needs to store all inventory data in Airtable so your company can easily manage and fulfill orders. You can setup a free Airtable account and add this Inventory Tracking template to your workspace to follow along.

Create a sync

To get started, you’ll need a Sequin account. If you don’t have one, you can sign up for free. Once you’re logged in, you’ll be taken to the Sequin Console:

  1. After selecting Airtable as your source, complete the authentication flow to connect your Airtable account to Sequin.
  2. Select the Airtable base you want to sync, in this case the “Inventory Tracking” template.
  3. Configure your schema by selecting the tables you want to sync. For now, select the Product Inventory table. You can change the tables and columns included in your sync at any time - we’ll cover that later.
  4. To get started, for the destination you can select a pre-configured, Sequin-hosted database. You’ll promote this sync to a database of your choice - perhaps your production database - later.
  5. After you click “Create”, Sequin will begin syncing your data. You can view the status of your sync in the Sequin Console.

Connect to your database

Now that you’ve created a sync, you can connect to your database and start building your integration. You’ll connect to your database just like any other Postgres database.

  1. You’ll find your connection credentials on the Connection instructions tab of your sync:
  2. Use the connection URL or the individual host, port, user, password, and database credentials to connect your database to your SQL client, ORM, or application.

You can see in the connection string that you’re connecting to your database using the Sequin Postgres Proxy. The proxy intercepts your SQL queries in order to apply mutations to the API as well as your database.

Selecting records

With your database connected, you can start reading and writing data. Get your bearings by selecting all the records from the product_inventory table:

select * from product_inventory;

Each column in the Airtable table is now a column in your database. The record_id for each record is stored in the id column. Run another query to see which product has the most inventory:

select id from product_inventory order by units_ordered desc limit 1;

You can also use where to filter records. For example, to find all products that cost more than $100:

select * from product_inventory where price > 100;

Adding new tables and columns

To make this a bit more interesting, let’s explore a join by adding another table to your sync.

You can add new tables and columns to your sync at any time. Sequin will automatically create the table and columns in your database and keep them in sync with your source.

  1. Go back to the Sequin Console and navigate to the Mapping tab of your sync.
  2. Select the Manufacturers table to include it in your sync.
  3. Now, edit the columns included in your sync. Perhaps you don’t want to include any PII in your database. You can exclude columns from your database by clicking the pencil button and deselecting the columns you don’t want to include - like email, phone number, and address:

After you click “Save changes”, we’ll run a migration on your database to add the manufacturers table. When the migration completes, you’ll see a new backfill job in the Sequin Console. This backfill job will backfill all the records from the manufacturers table into your database.

Now, when you connect to your database, you’ll see two tables. You can query across these tables with a join:

select
    manufacturers.name,
    product_inventory.product_name[1]
from product_inventory
join manufacturers on product_inventory.manufacturer[1] = manufacturers.id

Insert, update, and delete records

Now that you’re familiar with your database schema, write some data back to your source. You can insert, update, and delete records in your source using SQL.

Add a new product to your inventory:

insert into product_inventory (product_name, type, price)
values ('The Sequin', 'Box', 99)
returning id;

Notice that the moment your SQL statement returns, the new record is available in both Airtable and your database. The mutation is applied synchronously:

You’ll observe this true for updates as well. Change the price on the product you just inserted:

update product_inventory set price = 199 where product_name = 'The Sequin';

And you can delete records as well:

delete from product_inventory where product_name = 'The Sequin';

Errors

Sequin treats the API you’re syncing from as the source of truth. The business logic defined in Airtable is enforced on your database. For example, if you try to insert a record with an invalid type, you’ll get an error:

insert into product_inventory (product_name, type, price)
values ('The Sequin', 'Car', 99)
returning id;

ERROR:  Insufficient permissions to create new select option "Car" in field "Type"

This error is coming from Airtable but is being returned to you as a standard Postgres error. You can catch and handle this error in your application just like any other error.

Ship to production

You’ve built your integration and tested it in your your development environment using a Sequin-hosted database. Now you can point your sync to your production database and ship your integration. To do so, update your sync’s destination.

  1. Go back to the Sequin Console and navigate to the Settings tab of your sync.
  2. Scroll down to the Destination section and click Edit.
  3. Select Launch or Connect, click the Connect button, and follow the steps for connecting an external database.

After you connect your external database, Sequin will connect to it, create the new schema, and start syncing your data. You can view the status of your sync in the Sequin Console.

Cross schema queries

With your inventory data in your production database, you can now query across your entire database. For example, you can join your inventory data with your users table to see which products each user has purchased:

select
    users.id,
    users.email,
    airtable.product_inventory.product_name[1]
from users
join orders on users.id = orders.user_id
join airtable.product_inventory on orders.product_id = airtable.product_inventory.product_id;

Your application and Airtable data can now be queried and mutated through a single database!

Next steps

Now that you’ve created your sync, setup your schema, written your queries, and shipped to production, you’re ready to build out the rest of your integration. You can tune your sync and schema to fit your needs at any time in the Sequin Console. You can also use Sequin to sync data from multiple sources into a single database to simplify all your integrations. Check out our source specific guides and playbooks to learn more.