postgres-integration

command
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

PostgreSQL Integration Example

This example demonstrates a production-like setup where PostgreSQL is used for both:

  1. Persistence: Saving the scanner's current block height (cursor).
  2. Sink: Storing the actual event data into a relational table.

Prerequisites

  • A running PostgreSQL instance.
  • Set the PG_URL environment variable.

How to Run

  1. Start Postgres (using Docker):

    docker run --name some-postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres
    
  2. Run the example:

    export PG_URL="postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
    go run main.go
    

What happens?

  • The scanner will automatically create two tables:
    • demo_cursors: To track the last scanned block.
    • contract_events: To store decoded (or raw) logs with a unique constraint on (tx_hash, log_index) to prevent duplicates.
  • You can query the data using:
    SELECT * FROM contract_events ORDER BY block_number DESC;
    

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL