/ipfs-ds-postgres

🐘 PostgreSQL datastore for IPFS

Primary LanguageGoMIT LicenseMIT

ipfs-ds-postgres

Build Status Coverage Standard README GoDoc golang version Go Report Card

An implementation of the datastore interface for PostgreSQL that uses the pgx PostgreSQL driver.

Note: Currently implements Datastore and Batching interfaces.

Install

go get github.com/ipfs/ipfs-ds-postgres

Usage

Ensure a database is created and a table exists that has the following structure (replacing table_name with the name of the table the datastore will use - by default this is blocks):

CREATE TABLE IF NOT EXISTS table_name (key TEXT NOT NULL UNIQUE, data BYTEA)

It's recommended to create a text_pattern_ops index on the table:

CREATE INDEX IF NOT EXISTS table_name_key_text_pattern_ops_idx ON table_name (key text_pattern_ops)

Import and use in your application:

package main

import (
	"context"
	pgds "github.com/alanshaw/ipfs-ds-postgres"
)

const (
	connString = "postgresql://user:pass@host:12345/database?sslmode=require"
	tableName  = "blocks" // (default)
)

func main() {
	ds, err := pgds.NewDatastore(context.Background(), connString, pgds.Table(tableName))
	if err != nil {
		panic(err)
	}
}

API

GoDoc Reference

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw