Connecting to an External Database

Connecting to external database using reducers

This guide covers directly connecting Terrene to your database. It is not something we recommend but you can still do it. All the code in this guide should be run in a reducer.

Create SQLAlchemy Engine

Terrene supports SQLAlchemy outside of the box. To connect your database, please review their guide on creating an engine. In this example, we will connect to a Postgres database.

from sqlalchemy import create_engine
engine = create_engine(
'postgresql+psycopg2://scott:tiger@localhost:5432/mydatabase'
)

Please make sure your database is allowing connections from your instance's IP address. To find out the IP address of your instance, please contact support@terrene.co

Save Data to Table of Choice

content.to_sql("name_of_sql_table", con=engine, if_exists='replace')

This code will override the existing data if table names collide.

Export on Right Click Menu

After your code is complete, please create a custom code reducer and put the code in there. Then click on the settings icon on the top right corner

Then click on the "Convert to Atomic" button in the settings.

In supported data types, please select all options.

Finally, rename your custom code reducer to "Export to Database".

Then go to a TFrame you want to export, right click on any column, and then click on the "Export to Database".