Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #208 from yuce/adds-missing-index-field-options
Browse files Browse the repository at this point in the history
[Important] Added missing index/field options
  • Loading branch information
yuce authored Dec 7, 2018
2 parents 2b0c137 + 69694f5 commit 80d46dd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
35 changes: 21 additions & 14 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,29 +1197,36 @@ type SchemaField struct {

// SchemaOptions contains options for a field or an index.
type SchemaOptions struct {
FieldType FieldType `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint `json:"cacheSize"`
TimeQuantum string `json:"timeQuantum"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
FieldType FieldType `json:"type"`
CacheType string `json:"cacheType"`
CacheSize uint `json:"cacheSize"`
TimeQuantum string `json:"timeQuantum"`
Min int64 `json:"min"`
Max int64 `json:"max"`
Keys bool `json:"keys"`
NoStandardView bool `json:"noStandardView"`
TrackExistence bool `json:"trackExistence"`
}

func (so SchemaOptions) asIndexOptions() *IndexOptions {
return &IndexOptions{
keys: so.Keys,
keys: so.Keys,
keysSet: true,
trackExistence: so.TrackExistence,
trackExistenceSet: true,
}
}

func (so SchemaOptions) asFieldOptions() *FieldOptions {
return &FieldOptions{
fieldType: so.FieldType,
cacheSize: int(so.CacheSize),
cacheType: CacheType(so.CacheType),
timeQuantum: TimeQuantum(so.TimeQuantum),
min: so.Min,
max: so.Max,
fieldType: so.FieldType,
cacheSize: int(so.CacheSize),
cacheType: CacheType(so.CacheType),
timeQuantum: TimeQuantum(so.TimeQuantum),
min: so.Min,
max: so.Max,
keys: so.Keys,
noStandardView: so.NoStandardView,
}
}

Expand Down
23 changes: 19 additions & 4 deletions client_it_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,28 +570,43 @@ func TestSchema(t *testing.T) {
if len(schema.indexes) < 1 {
t.Fatalf("There should be at least 1 index in the schema")
}
index := schema.Index("schema-test-index",
OptIndexKeys(true),
OptIndexTrackExistence(false))
f := index.Field("schema-test-field",
OptFieldTypeSet(CacheTypeLRU, 9999),
OptFieldKeys(true),
)
err = client.EnsureField(f)
err = client.SyncSchema(schema)
if err != nil {
t.Fatal(err)
}
schema, err = client.Schema()
if err != nil {
t.Fatal(err)
}
f = schema.indexes[index.Name()].fields["schema-test-field"]
if f == nil {
i2 := schema.indexes[index.Name()]
if !reflect.DeepEqual(index.options, i2.options) {
t.Fatalf("%v != %v", index.options, i2.options)
}

f2 := schema.indexes[index.Name()].fields["schema-test-field"]
if f2 == nil {
t.Fatal("Field should not be nil")
}
opt := f.options
opt := f2.options
if opt.cacheType != CacheTypeLRU {
t.Fatalf("cache type %s != %s", CacheTypeLRU, opt.cacheType)
}
if opt.cacheSize != 9999 {
t.Fatalf("cache size 9999 != %d", opt.cacheSize)
}
if !opt.keys {
t.Fatalf("keys true != %v", opt.keys)
}
if !reflect.DeepEqual(f.options, f2.options) {
t.Fatalf("%v != %v", f.options, f2.options)
}
}

func TestSync(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ func (io *IndexOptions) withDefaults() (updated *IndexOptions) {
return
}

func (io IndexOptions) Keys() bool {
return io.keys
}

func (io IndexOptions) TrackExistence() bool {
return io.trackExistence
}

func (io IndexOptions) String() string {
mopt := map[string]interface{}{}
if io.keysSet {
Expand Down Expand Up @@ -582,6 +590,12 @@ func (fo *FieldOptions) Max() int64 {
return fo.max
}

// Keys returns whether this field uses keys instead of IDs
func (fo *FieldOptions) Keys() bool {
return fo.keys
}

// NoStandardView suppresses creating the standard view for supported field types (currently, time)
func (fo *FieldOptions) NoStandardView() bool {
return fo.noStandardView
}
Expand Down

0 comments on commit 80d46dd

Please sign in to comment.