Skip to content

Should schema.Schema, Fields and FieldValidators be splitt into a compiled and uncompiled type? #194

@smyrman

Description

@smyrman

A discussion in #109 suggest distinguishing between a resource.IndexBuilder (allows adding resources, and returning a compiled index) and resource.Index (allows finding active resources and fetching items).

There are some reasons that could make it worthwhile to take a similar approach for schema.Schema:

  • FieldValidors are often referred to as pointers (e.g. schema.IDField, to mention one). When the Field definition is reused in multiple schemas, or the same schema is compiled multiple times in parallel, e.g. for tests, a data race condition arise. When CIs run the tests with race detection enabled, they are likely to fail.
  • We could avoid doing things like Move FieldValidator Validate() methods to be be on a pointer value #110 - instead, .Compile would be a method on a FieldValidatorBuilder returning a FieldValidator (naming not final).
  • We won't be able to accidentally use an uncompiled schema in place of a compiled one.

This changes should be considered alongside other potentially large schema package changes, such as #77, that basically suggests allowing any FieldValidator to be used a the Schema top-level.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions