Skip to content

Add support for custom struct tags #534

Closed
@philippta

Description

@philippta

When working with structs, struct tags are used to add additional information to a field. This is for example very common when using validation packages. But currently there is no way to add additional struct tags to take advantage of this.

I think it would be a great idea to add a comment syntax just like the -- name:NameForQuery for table columns.

A possible option to express these custom struct tags would be to write create table statements like this:

CREATE TABLE user (
  id   BIGSERIAL PRIMARY KEY,

  -- tags:`validate:"min=10,max=0"`
  username text NOT NULL,

  -- tags:`validate:"gt=18"`
  age  integer NOT NULL,

  -- tags:`validate:"url"`
  website text NOT NULL
);

or alternatively:

CREATE TABLE user (
  id   BIGSERIAL PRIMARY KEY,
  username text NOT NULL,     -- tags:`validate:"min=10,max=0"`
  age integer NOT NULL,       -- tags:`validate:"gt=18"`
  website text NOT NULL       -- tags:`validate:"url"`
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions