Tezos Dappetizer
  • Quick Start
  • How-to Guides
    • Using PostgreSQL
    • Exposing API with Hasura
  • Reference
    • Decorator-based Indexing
      • Indexing Entrypoint Call
      • Indexing Storage Change
      • Indexing Bigmap Update
      • Indexing Incoming Transaction
    • Interface-based Indexing
    • Configuration
    • Command Line
    • Usage Statistics
  • Technical Concepts
    • Indexing Cycle
    • Indexer Modules
  • Token Indexer
    • Introduction
    • Running Standalone in Docker
  • API Docs
  • dappetizer GitLab
Powered by GitBook
On this page
  • Prerequisites
  • Setting up a local database
  • Installing PostgreSQL package
  • Configuring Dappetizer
  • Checking the generated data

Was this helpful?

  1. How-to Guides

Using PostgreSQL

PreviousQuick StartNextExposing API with Hasura

Last updated 3 years ago

Was this helpful?

Using PostgreSQL with Dappetizer is really straightforward and can be set up in a few minutes.

Prerequisites

You will need the following for this guide:

  • For the purposes of this guide, we will assume you already have an existing Dappetizer project. Check out our guide to learn how to set up one.

  • (if you are planning on running PostgreSQL in Docker) or a full instance

Setting up a local database

If you don't have a local PostgreSQL instance running, you can start one using :

docker run -d \
	--name dev-postgres \
	-e POSTGRES_PASSWORD=postgrespassword \
	-v ${HOME}/postgres-data/:/var/lib/postgresql/data \
        -p 5432:5432 \
        postgres

Installing PostgreSQL package

The PostgreSQL client package is required when connecting to the database. To install it, run

npm install pg

Configuring Dappetizer

database: {
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'postgres',
    password: 'postgrespassword',
    database: 'postgres',
    schema: 'indexer',
},

Notice that the username and password here are stored in plaintext. That is fine for local development, but when running Dappetizer on a server, you should use a local configuration file stored on the server (the file should not be in source control) or make use of environment variables. For example, this is how you can use environment variables:

database: {
    type: 'postgres',
    host: process.env['MY_HOST_VARIABLE'],
    port: 5432,
    username: process.env['MY_USERNAME_VARIABLE'],
    password: process.env['MY_PASSWORD_VARIABLE'],
    database: 'postgres',
    schema: 'indexer',
},

Checking the generated data

docker run -it --rm --network=host postgres psql -h localhost -U postgres

To select what blocks have been saved by the indexer, we will run a short SELECT query:

select * from indexer.block limit 10;

If the indexer has successfully connected to the database and started indexing, you should be able to see the stored blocks so far.

The should be changed with specific settings for connecting to PostgreSQL. To connect to your local instance, you can replace the existing database section with:

You can use any tool (like ) to connect to the database. In this guide we will simply use Docker to run :

Quick Start
Docker
PostgreSQL
Docker
configuration
pgAdmin
psql