diff --git a/client.go b/client.go index 45c2397..c08b705 100644 --- a/client.go +++ b/client.go @@ -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, } } diff --git a/client_it_test.go b/client_it_test.go index 796467d..0d2d314 100644 --- a/client_it_test.go +++ b/client_it_test.go @@ -570,10 +570,14 @@ 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) } @@ -581,17 +585,28 @@ func TestSchema(t *testing.T) { 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) { diff --git a/orm.go b/orm.go index 5ac9543..806a3b2 100644 --- a/orm.go +++ b/orm.go @@ -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 { @@ -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 }