From 178e0d77279ddbd8adad2bbe1aa4bf48cc0bc77c Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Mon, 2 Oct 2023 13:20:28 -0400 Subject: [PATCH] fixup! WIP - Move refs from c.desc.Schema to c.Schema --- db/index.go | 3 +-- http/client.go | 8 ++++---- http/client_collection.go | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/db/index.go b/db/index.go index 42ae92edfa..cf58cd6ba2 100644 --- a/db/index.go +++ b/db/index.go @@ -86,8 +86,7 @@ func NewCollectionIndex( return nil, NewErrIndexDescHasNoFields(desc) } index := &collectionSimpleIndex{collection: collection, desc: desc} - schema := collection.Description().Schema - field, foundField := schema.GetField(desc.Fields[0].Name) + field, foundField := collection.Schema().GetField(desc.Fields[0].Name) if !foundField { return nil, NewErrIndexDescHasNonExistingField(desc, desc.Fields[0].Name) } diff --git a/http/client.go b/http/client.go index 867cdc3bb1..9b802f6164 100644 --- a/http/client.go +++ b/http/client.go @@ -264,7 +264,7 @@ func (c *Client) GetCollectionByName(ctx context.Context, name client.Collection if err := c.http.requestJson(req, &description); err != nil { return nil, err } - return &Collection{c.http, description}, nil + return &Collection{c.http, description, description.Schema}, nil } func (c *Client) GetCollectionBySchemaID(ctx context.Context, schemaId string) (client.Collection, error) { @@ -279,7 +279,7 @@ func (c *Client) GetCollectionBySchemaID(ctx context.Context, schemaId string) ( if err := c.http.requestJson(req, &description); err != nil { return nil, err } - return &Collection{c.http, description}, nil + return &Collection{c.http, description, description.Schema}, nil } func (c *Client) GetCollectionByVersionID(ctx context.Context, versionId string) (client.Collection, error) { @@ -294,7 +294,7 @@ func (c *Client) GetCollectionByVersionID(ctx context.Context, versionId string) if err := c.http.requestJson(req, &description); err != nil { return nil, err } - return &Collection{c.http, description}, nil + return &Collection{c.http, description, description.Schema}, nil } func (c *Client) GetAllCollections(ctx context.Context) ([]client.Collection, error) { @@ -310,7 +310,7 @@ func (c *Client) GetAllCollections(ctx context.Context) ([]client.Collection, er } collections := make([]client.Collection, len(descriptions)) for i, d := range descriptions { - collections[i] = &Collection{c.http, d} + collections[i] = &Collection{c.http, d, d.Schema} } return collections, nil } diff --git a/http/client_collection.go b/http/client_collection.go index 16157a9f96..5690ece3c2 100644 --- a/http/client_collection.go +++ b/http/client_collection.go @@ -31,8 +31,9 @@ var _ client.Collection = (*Collection)(nil) // Collection implements the client.Collection interface over HTTP. type Collection struct { - http *httpClient - desc client.CollectionDescription + http *httpClient + desc client.CollectionDescription + schema client.SchemaDescription } func (c *Collection) Description() client.CollectionDescription { @@ -44,7 +45,7 @@ func (c *Collection) Name() string { } func (c *Collection) Schema() client.SchemaDescription { - return c.desc.Schema + return c.schema } func (c *Collection) ID() uint32 { @@ -52,7 +53,7 @@ func (c *Collection) ID() uint32 { } func (c *Collection) SchemaID() string { - return c.desc.Schema.SchemaID + return c.Schema().SchemaID } func (c *Collection) Create(ctx context.Context, doc *client.Document) error { @@ -60,7 +61,7 @@ func (c *Collection) Create(ctx context.Context, doc *client.Document) error { // We must call this here, else the doc key on the given object will not match // that of the document saved in the database - err := doc.RemapAliasFieldsAndDockey(c.Description().Schema.Fields) + err := doc.RemapAliasFieldsAndDockey(c.Schema().Fields) if err != nil { return err } @@ -88,7 +89,7 @@ func (c *Collection) CreateMany(ctx context.Context, docs []*client.Document) er for _, doc := range docs { // We must call this here, else the doc key on the given object will not match // that of the document saved in the database - err := doc.RemapAliasFieldsAndDockey(c.Description().Schema.Fields) + err := doc.RemapAliasFieldsAndDockey(c.Schema().Fields) if err != nil { return err } @@ -318,8 +319,9 @@ func (c *Collection) Get(ctx context.Context, key client.DocKey, showDeleted boo func (c *Collection) WithTxn(tx datastore.Txn) client.Collection { return &Collection{ - http: c.http.withTxn(tx.ID()), - desc: c.desc, + http: c.http.withTxn(tx.ID()), + desc: c.desc, + schema: c.schema, } }