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, } } diff --git a/net/process.go b/net/process.go index a2fd446cfe..c07800b51f 100644 --- a/net/process.go +++ b/net/process.go @@ -102,7 +102,7 @@ func initCRDTForType( core.COMPOSITE_NAMESPACE, ) } else { - fd, ok := description.Schema.GetField(field) + fd, ok := col.Schema().GetField(field) if !ok { return nil, errors.New(fmt.Sprintf("Couldn't find field %s for doc %s", field, dsKey)) } diff --git a/planner/commit.go b/planner/commit.go index e6216e2b43..c2cff28c30 100644 --- a/planner/commit.go +++ b/planner/commit.go @@ -333,7 +333,7 @@ func (n *dagScanNode) dagBlockToNodeDoc(block blocks.Block) (core.Doc, []*ipld.L return core.Doc{}, nil, err } - field, ok := c.Description().Schema.GetField(fieldName.(string)) + field, ok := c.Schema().GetField(fieldName.(string)) if !ok { return core.Doc{}, nil, client.NewErrFieldNotExist(fieldName.(string)) }