github.com/leg100/ots@v0.0.7-0.20210919080622-034055ced4bd/sqlite/state_version_output_model.go (about)

     1  package sqlite
     2  
     3  import (
     4  	"github.com/leg100/ots"
     5  	"gorm.io/gorm"
     6  )
     7  
     8  // StateVersionOutput models a row in a state versions table.
     9  type StateVersionOutput struct {
    10  	gorm.Model
    11  
    12  	ExternalID string `gorm:"uniqueIndex"`
    13  
    14  	Name      string
    15  	Sensitive bool
    16  	Type      string
    17  	Value     string
    18  
    19  	// StateVersionOutput belongs to State Version
    20  	StateVersionID uint
    21  }
    22  
    23  // StateVersionOutputList is a list of run models
    24  type StateVersionOutputList []StateVersionOutput
    25  
    26  func (model *StateVersionOutput) ToDomain() *ots.StateVersionOutput {
    27  	domain := ots.StateVersionOutput{
    28  		ID:        model.ExternalID,
    29  		Name:      model.Name,
    30  		Sensitive: model.Sensitive,
    31  		Type:      model.Type,
    32  		Value:     model.Value,
    33  	}
    34  
    35  	return &domain
    36  }
    37  
    38  // NewStateVersionOutputFromDomain constructs a model obj from a domain obj
    39  func NewStateVersionOutputFromDomain(domain *ots.StateVersionOutput) *StateVersionOutput {
    40  	return &StateVersionOutput{
    41  		ExternalID: domain.ID,
    42  		Name:       domain.Name,
    43  		Sensitive:  domain.Sensitive,
    44  		Type:       domain.Type,
    45  		Value:      domain.Value,
    46  	}
    47  }
    48  
    49  func (l StateVersionOutputList) ToDomain() (dl []*ots.StateVersionOutput) {
    50  	for _, i := range l {
    51  		dl = append(dl, i.ToDomain())
    52  	}
    53  	return
    54  }