diff --git a/bbolt/bbolt.go b/bbolt/bbolt.go index 3af8cfd..be9588c 100644 --- a/bbolt/bbolt.go +++ b/bbolt/bbolt.go @@ -2,6 +2,7 @@ package bbolt import ( "errors" + "os" "github.com/simar7/gokv/types" @@ -247,3 +248,15 @@ func (s Store) Scan(input types.ScanInput) (types.ScanOutput, error) { func (s Store) Close() error { return s.db.Close() } + +func (s Store) Info() (types.StoreInfo, error) { + f, err := os.Stat(s.dbPath) + if err != nil { + return types.StoreInfo{}, err + } + + return types.StoreInfo{ + Name: s.rbc.Name, + Size: f.Size(), + }, nil +} diff --git a/bbolt/bbolt_test.go b/bbolt/bbolt_test.go index 7b258aa..03edcca 100644 --- a/bbolt/bbolt_test.go +++ b/bbolt/bbolt_test.go @@ -7,14 +7,13 @@ import ( "sync" "testing" - "github.com/simar7/gokv/encoding" - - "github.com/simar7/gokv/util" - bolt "go.etcd.io/bbolt" + h "github.com/dustin/go-humanize" + "github.com/simar7/gokv/encoding" "github.com/simar7/gokv/types" - + "github.com/simar7/gokv/util" "github.com/stretchr/testify/assert" + bolt "go.etcd.io/bbolt" ) func setupStoreWithCodec(codec encoding.Codec) (*Store, *os.File, error) { @@ -369,3 +368,17 @@ func TestStore_Scan(t *testing.T) { assert.Empty(t, scanOut) }) } + +func TestStore_Info(t *testing.T) { + s, f, err := setupStore() + defer func() { + _ = f.Close() + _ = os.RemoveAll(f.Name()) + }() + assert.NoError(t, err) + + actualInfo, err := s.Info() + assert.NoError(t, err) + assert.Equal(t, "gokvbbolt", actualInfo.Name) + assert.Equal(t, "32 KiB", h.IBytes(uint64(actualInfo.Size))) +} diff --git a/dynamodb/dynamodb.go b/dynamodb/dynamodb.go index 4860590..418ebed 100644 --- a/dynamodb/dynamodb.go +++ b/dynamodb/dynamodb.go @@ -25,7 +25,7 @@ var ( var ( ErrMissingTableName = errors.New("table name is required") - //ErrNotImplemented = errors.New("function not implemented") + ErrNotImplemented = errors.New("function not implemented") ) type Options struct { @@ -245,3 +245,7 @@ func (s Store) Scan(input types.ScanInput) (types.ScanOutput, error) { return scanOuput, nil } + +func (s Store) Info() (types.StoreInfo, error) { + return types.StoreInfo{}, ErrNotImplemented +} diff --git a/go.mod b/go.mod index 4ddab09..cc59be3 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/alicebob/miniredis/v2 v2.11.0 github.com/aws/aws-sdk-go v1.25.31 github.com/davecgh/go-spew v1.1.0 + github.com/dustin/go-humanize v1.0.0 github.com/gomodule/redigo v2.0.0+incompatible github.com/stretchr/testify v1.4.0 go.etcd.io/bbolt v1.3.3 diff --git a/go.sum b/go.sum index 62b9493..dcf84f7 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/gomodule/redigo v1.7.1-0.20190322064113-39e2c31b7ca3/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= diff --git a/redis/redis.go b/redis/redis.go index 1babbad..3ab89a4 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -17,6 +17,7 @@ var ( ErrInvalidAddress = errors.New("invalid redis address specified") ErrRedisInitFailed = errors.New("redis initialization failed") ErrKeyNotFound = errors.New("key not found") + ErrNotImplemented = errors.New("function not implemented") ) type Options struct { @@ -243,3 +244,7 @@ func (s Store) getAllKeys() ([]string, error) { } return keys, nil } + +func (s Store) Info() (types.StoreInfo, error) { + return types.StoreInfo{}, ErrNotImplemented +} diff --git a/store.go b/store.go index d7b1558..3385c8d 100644 --- a/store.go +++ b/store.go @@ -9,4 +9,5 @@ type Store interface { Delete(input types.DeleteItemInput) error Close() error Scan(input types.ScanInput) (types.ScanOutput, error) + Info() (types.StoreInfo, error) } diff --git a/types/types.go b/types/types.go index 0fee9b5..2dd489f 100644 --- a/types/types.go +++ b/types/types.go @@ -31,3 +31,8 @@ type ScanOutput struct { Keys []string `dynamodbav:"k"` Values [][]byte `dynamodbav:"v"` } + +type StoreInfo struct { + Name string + Size int64 +}