Skip to content

Commit

Permalink
fixup! WIP - Move refs from c.desc.Schema to c.Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Oct 2, 2023
1 parent 4a4e605 commit 70daf0f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
3 changes: 1 addition & 2 deletions db/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
18 changes: 10 additions & 8 deletions http/client_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -44,23 +45,23 @@ func (c *Collection) Name() string {
}

func (c *Collection) Schema() client.SchemaDescription {
return c.desc.Schema
return c.schema
}

func (c *Collection) ID() uint32 {
return c.desc.ID
}

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 {
methodURL := c.http.baseURL.JoinPath("collections", c.desc.Name)

// 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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion net/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion planner/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit 70daf0f

Please sign in to comment.