diff --git a/.gitignore b/.gitignore index 1e21b5cc2fe6..8cf45a5e6e4d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ bin/tmp vendor .tarball go-ipfs-source.tar.gz + +.idea diff --git a/repo/fsrepo/datastores.go b/repo/fsrepo/datastores.go index aaffbcab999e..cd070825154a 100644 --- a/repo/fsrepo/datastores.go +++ b/repo/fsrepo/datastores.go @@ -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" @@ -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, } } @@ -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 +}