From a7bb2e22094ee8788fe1b4ef6b7045c9fbd996ee Mon Sep 17 00:00:00 2001 From: postables Date: Tue, 12 May 2020 23:02:42 -0700 Subject: [PATCH] sql: update readme --- sql/README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/sql/README.md b/sql/README.md index e996ff9..e5980be 100644 --- a/sql/README.md +++ b/sql/README.md @@ -13,7 +13,39 @@ ## Easy (Automatic) -The `postgres` datastore has some helper utility to enable automatic table and index creation, as well as the ability to recreate the table by dropping it, and creating it. +The `postgres` datastore has some helper utility to enable automatic table and index creation, as well as the ability to recreate the table by dropping it, and creating it. The following will make it easy to do this: + + +```Go +import ( + pgds "github.com/RTradeLtd/go-datastores/sql/postgres" + "github.com/ipfs/go-datastore" +) +opts := &pgds.Options{ + Host: "127.0.0.1", + Port: "5432", + User: "postgres", + Database: "datastores", + Password: "password123", + SSLMode: "disable", + Table: "blocks", + // this will dropthe existing table + AcceptRecreateWarning: pgds.AcceptTableRecreationWarning, + RunMigrations: true, + RecreateTables: true, + CreateIndex: true, +} +ds, err := opts.Create() +if err != nil { + log.Fatal(err) +} +if err := ds.Put( + datastore.NewKey("much test very wow"), + []byte("whose even going to read this anyways"), +); err != nil { + log.Fatal(err) +} +``` ## Hard (Manual)