github.com/willyham/dosa@v2.3.1-0.20171024181418-1e446d37ee71+incompatible/connectors/devnull/devnull.go (about) 1 // Copyright (c) 2017 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package devnull 22 23 import ( 24 "context" 25 26 "github.com/uber-go/dosa" 27 ) 28 29 // Connector is a connector implementation for testing 30 type Connector struct{} 31 32 // CreateIfNotExists always returns nil 33 func (c *Connector) CreateIfNotExists(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error { 34 return nil 35 } 36 37 // Read always returns a not found error 38 func (c *Connector) Read(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue, minimumFields []string) (map[string]dosa.FieldValue, error) { 39 return nil, &dosa.ErrNotFound{} 40 } 41 42 // MultiRead returns a set of not found errors for each key you specify 43 func (c *Connector) MultiRead(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue, minimumFields []string) ([]*dosa.FieldValuesOrError, error) { 44 errors := make([]*dosa.FieldValuesOrError, len(values)) 45 for inx := range values { 46 errors[inx] = &dosa.FieldValuesOrError{Error: &dosa.ErrNotFound{}} 47 } 48 return errors, nil 49 } 50 51 // Upsert throws away the data you upsert 52 func (c *Connector) Upsert(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error { 53 return nil 54 } 55 56 // makeErrorSlice is a handy function to make a slice of errors or nil errors 57 func makeErrorSlice(len int, e error) []error { 58 errors := make([]error, len) 59 for inx := 0; inx < len; inx = inx + 1 { 60 errors[inx] = e 61 } 62 return errors 63 } 64 65 // MultiUpsert throws away all the data you upsert, returning a set of no errors 66 func (c *Connector) MultiUpsert(ctx context.Context, ei *dosa.EntityInfo, values []map[string]dosa.FieldValue) ([]error, error) { 67 return makeErrorSlice(len(values), nil), nil 68 } 69 70 // Remove always returns a not found error 71 func (c *Connector) Remove(ctx context.Context, ei *dosa.EntityInfo, values map[string]dosa.FieldValue) error { 72 return nil 73 } 74 75 // RemoveRange removes all entities within the range specified by the columnConditions. 76 func (c *Connector) RemoveRange(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition) error { 77 return nil 78 } 79 80 // MultiRemove returns a not found error for each value 81 func (c *Connector) MultiRemove(ctx context.Context, ei *dosa.EntityInfo, multiValues []map[string]dosa.FieldValue) ([]error, error) { 82 return makeErrorSlice(len(multiValues), &dosa.ErrNotFound{}), nil 83 } 84 85 // Range is not yet implementedS 86 func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, columnConditions map[string][]*dosa.Condition, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) { 87 return nil, "", &dosa.ErrNotFound{} 88 } 89 90 // Scan is not yet implemented 91 func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) { 92 return nil, "", &dosa.ErrNotFound{} 93 } 94 95 // CheckSchema always returns a slice of int32 values that match its index 96 func (c *Connector) CheckSchema(ctx context.Context, scope, namePrefix string, ed []*dosa.EntityDefinition) (int32, error) { 97 return int32(1), nil 98 } 99 100 // UpsertSchema always returns a slice of int32 values that match its index 101 func (c *Connector) UpsertSchema(ctx context.Context, scope, namePrefix string, ed []*dosa.EntityDefinition) (*dosa.SchemaStatus, error) { 102 return &dosa.SchemaStatus{Version: int32(1), Status: "COMPLETED"}, nil 103 } 104 105 // CheckSchemaStatus always returns a SchemaStatus with version 1 and ACCEPTED status 106 func (c *Connector) CheckSchemaStatus(ctx context.Context, scope, namePrefix string, version int32) (*dosa.SchemaStatus, error) { 107 return &dosa.SchemaStatus{ 108 Version: int32(1), 109 Status: "ACCEPTED", 110 }, nil 111 } 112 113 // CreateScope returns success 114 func (c *Connector) CreateScope(ctx context.Context, scope string) error { 115 return nil 116 } 117 118 // TruncateScope returns success 119 func (c *Connector) TruncateScope(ctx context.Context, scope string) error { 120 return nil 121 } 122 123 // DropScope returns success 124 func (c *Connector) DropScope(ctx context.Context, scope string) error { 125 return nil 126 } 127 128 // ScopeExists returns true 129 func (c *Connector) ScopeExists(ctx context.Context, scope string) (bool, error) { 130 return true, nil 131 } 132 133 // Shutdown always returns nil 134 func (c *Connector) Shutdown() error { 135 return nil 136 } 137 138 // NewConnector creates a new devnull connector 139 func NewConnector() *Connector { 140 return &Connector{} 141 } 142 143 func init() { 144 dosa.RegisterConnector("devnull", func(dosa.CreationArgs) (dosa.Connector, error) { 145 return &Connector{}, nil 146 }) 147 }