Skip to main content
Easily integrate your app with or . Use your favorite programming language to connect to your , create and manage s, then ingest and query data.

Prerequisites

To follow the steps on this page:
  • Create a target with Real-time analytics enabled.

    You need your connection details. This procedure also works for .

Connect a Rails app to your service

Every is a 100% database hosted in with extensions such as . You connect to your from a standard Rails app configured for .
  1. Create a new Rails app configured for Rails creates and bundles your app, then installs the standard Gems.
  2. Install the gem
    1. Open Gemfile, add the following line, then save your changes:
    2. In Terminal, run the following command:
  3. Connect your app to your
    1. In <my_app_home>/config/database.yml update the configuration to read securely connect to your by adding url: <%= ENV['DATABASE_URL'] %> to the default configuration:
    2. Set the environment variable for DATABASE_URL to the value of Service URL from your connection details
    3. Create the database:
      • : nothing to do. The database is part of your .
      • , create the database for the project:
    4. Run migrations:
    5. Verify the connection from your app to your :
      The result shows the list of extensions in your

Optimize time-series data in hypertables

s are tables designed to simplify and accelerate data analysis. Anything you can do with regular tables, you can do with s - but much faster and more conveniently.In this section, you use the helpers in the gem to create and manage a .
  1. Generate a migration to create the page loads table
    This creates the <my_app_home>/db/migrate/<migration-datetime>_create_page_loads.rb migration file.
  2. Add hypertable options Replace the contents of <my_app_home>/db/migrate/<migration-datetime>_create_page_loads.rb with the following:
    The id column is not included in the table. This is because requires that any UNIQUE or PRIMARY KEY indexes on the table include all partitioning columns. In this case, this is the time column. A new Rails model includes a PRIMARY KEY index for id by default: either remove the column or make sure that the index includes time as part of a “composite key.” For more information, check the Ruby docs around composite primary keys.
  3. Create a PageLoad model Create a new file called <my_app_home>/app/models/page_load.rb and add the following code:
  4. Run the migration

Insert data your service

The gem provides efficient ways to insert data into s. This section shows you how to ingest test data into your .
  1. Create a controller to handle page loads Create a new file called <my_app_home>/app/controllers/application_controller.rb and add the following code:
  2. Generate some test data Use bin/console to join a Rails console session and run the following code to define some random page load access data:
  3. Insert the generated data into your
  4. Validate the test data in your

Reference

This section lists the most common tasks you might perform with the gem.

Query scopes

The gem provides several convenient scopes for querying your time-series data.
  • Built-in time-based scopes:
  • Browser-specific scopes:
  • Query s: This query fetches the average and standard deviation from the performance stats for the /products path over the last day.

TimescaleDB features

The gem provides utility methods to access and information. Every model that uses the acts_as_hypertable method has access to these methods.

Access hypertable and chunk information

  • View or information:
  • Compress/Decompress s:

Access hypertable stats

You collect stats using methods that provide insights into your ‘s structure, size, and compression status:
  • Get basic information:
  • Get detailed size information:

Continuous aggregates

The continuous_aggregates method generates a class for each .
  • Get all the classes:
  • Manually refresh a :
  • Create or drop a : Create or drop all the s in the proper order to build them hierarchically. See more about how it works in this blog post.

Next steps

Now that you have integrated the ruby gem into your app:
You are not limited to these languages. is based on , you can interface with and using any client driver.