Skip to content

Commit

Permalink
Add postgres datastore type
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: User Name <email@address>
  • Loading branch information
JamesChristie committed Aug 27, 2018
1 parent 93c4f19 commit ce3bfc2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ bin/tmp
vendor
.tarball
go-ipfs-source.tar.gz

.idea
49 changes: 42 additions & 7 deletions repo/fsrepo/datastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

repo "github.com/ipfs/go-ipfs/repo"

postgresdb "github.com/whyrusleeping/sql-datastore/postgres"
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
measure "gx/ipfs/QmRa2HJZNKkkkbNVPkZu9VCzst4B3JmxoaR97EUFhWcK6m/go-ds-measure"
flatfs "gx/ipfs/QmU8mLmWDS1SKmqrRUiiedxkFE9gUuST6ggpWM8jAon27d/go-ds-flatfs"
Expand Down Expand Up @@ -58,13 +59,14 @@ var datastores map[string]ConfigFromMap

func init() {
datastores = map[string]ConfigFromMap{
"mount": MountDatastoreConfig,
"flatfs": FlatfsDatastoreConfig,
"levelds": LeveldsDatastoreConfig,
"badgerds": BadgerdsDatastoreConfig,
"mem": MemDatastoreConfig,
"log": LogDatastoreConfig,
"measure": MeasureDatastoreConfig,
"mount": MountDatastoreConfig,
"flatfs": FlatfsDatastoreConfig,
"levelds": LeveldsDatastoreConfig,
"badgerds": BadgerdsDatastoreConfig,
"postgresds": PostgresDatastoreConfig,
"mem": MemDatastoreConfig,
"log": LogDatastoreConfig,
"measure": MeasureDatastoreConfig,
}
}

Expand Down Expand Up @@ -410,3 +412,36 @@ func (c *badgerdsDatastoreConfig) Create(path string) (repo.Datastore, error) {

return badgerds.NewDatastore(p, &defopts)
}

// PostgresDatastoreConfig returns a postgres DatastoreConfig from a spec
func PostgresDatastoreConfig(params map[string]interface{}) (DatastoreConfig, error) {
var c postgresDatastoreConfig
var ok bool
c.path, ok = params["path"].(string)
if !ok {
log.Fatal("no path")
}

return &c, nil
}

type postgresDatastoreConfig struct {
path string
}

func (c *postgresDatastoreConfig) DiskSpec() DiskSpec {
return map[string]interface{}{
"type": "postgresds",
"path": c.path,
}
}

func (postgresDatastoreConfig) Create(path string) (repo.Datastore, error) {
pg := postgresdb.Options{}
ds, err := pg.Create()
if err != nil {
fmt.Println("error loading pg: ", err)
return ds, err
}
return ds, nil
}

0 comments on commit ce3bfc2

Please sign in to comment.