Skip to content

Question: What reform uses for UUID support #202

@rumyantseva

Description

@rumyantseva

When my model has a UUID-based field and when I do reform models I have the following situation:

  1. Reform generates the code but doesn't add anything to imports. Personally, I use github.com/satori/go.uuid for uuid. I wonder, if I can add something to reform to be able to support this import automatically.

  2. Reform generates the following method:

// SetPK sets record primary key.
func (s *Profile) SetPK(pk interface{}) {
	if i64, ok := pk.(int64); ok {
		s.ID = uuid.UUID(i64)
	} else {
		s.ID = pk.(uuid.UUID)
	}
}

As nothing has been added to imports, I wonder which library supports uuid.UUID(i64) (as this is not what satori/go.uuid can offer, it gives me cannot convert i64 (type int64) to type uuid.UUID). I found a way to make my code working:

func (s *Profile) SetPK(pk interface{}) {
	s.ID = pk.(uuid.UUID)
}

But I wonder if this is a suitable approach and how can I improve the whole story.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions