An implementation of the datastore interface for PostgreSQL that uses the pgx PostgreSQL driver.
Note: Currently implements Datastore and Batching interfaces.
go get github.com/alanshaw/ipfs-ds-postgresEnsure 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)
}
}Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw