parent
62734899e2
commit
d46e721063
15 changed files with 71 additions and 14 deletions
|
@ -32,6 +32,10 @@ func (c *CharacteristicBase) UpdateError() error {
|
|||
return errors.ErrCharacteristicNotUpdated
|
||||
}
|
||||
|
||||
func (c *CharacteristicBase) DeleteError() error {
|
||||
return errors.ErrCharacteristicNotDeleted
|
||||
}
|
||||
|
||||
// CharacteristicBase is what the DB expects for write operations
|
||||
type CharacteristicBase struct {
|
||||
ID int64 `json:"id,omitempty"`
|
||||
|
|
|
@ -6,6 +6,7 @@ type base interface {
|
|||
PreInsert(modl.SqlExecutor) error
|
||||
PreUpdate(modl.SqlExecutor) error
|
||||
UpdateError() error
|
||||
DeleteError() error
|
||||
}
|
||||
|
||||
// Create will create a new DB record of a model.
|
||||
|
@ -27,3 +28,15 @@ func Update(b base) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete runs a DB delete on a model.
|
||||
func Delete(b base) error {
|
||||
count, err := DBH.Delete(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count != 1 {
|
||||
return b.DeleteError()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ func (m *MeasurementBase) UpdateError() error {
|
|||
return errors.ErrMeasurementNotUpdated
|
||||
}
|
||||
|
||||
func (m *MeasurementBase) DeleteError() error {
|
||||
return errors.ErrMeasurementNotDeleted
|
||||
}
|
||||
|
||||
// MeasurementBase is what the DB expects for write operations
|
||||
// There are three types of supported measurements: fixed-text, free-text,
|
||||
// & numerical. The table has a constraint that will allow at most one
|
||||
|
|
|
@ -33,6 +33,10 @@ func (s *SpeciesBase) UpdateError() error {
|
|||
return errors.ErrSpeciesNotUpdated
|
||||
}
|
||||
|
||||
func (s *SpeciesBase) DeleteError() error {
|
||||
return errors.ErrSpeciesNotDeleted
|
||||
}
|
||||
|
||||
// SpeciesBase is what the DB expects for write operations.
|
||||
type SpeciesBase struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
|
|
|
@ -33,6 +33,10 @@ func (s *StrainBase) UpdateError() error {
|
|||
return errors.ErrStrainNotUpdated
|
||||
}
|
||||
|
||||
func (s *StrainBase) DeleteError() error {
|
||||
return errors.ErrStrainNotDeleted
|
||||
}
|
||||
|
||||
// StrainBase is what the DB expects for write operations.
|
||||
type StrainBase struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
|
|
|
@ -34,6 +34,10 @@ func (u *UserBase) UpdateError() error {
|
|||
return errors.ErrUserNotUpdated
|
||||
}
|
||||
|
||||
func (u *UserBase) DeleteError() error {
|
||||
return errors.ErrUserNotDeleted
|
||||
}
|
||||
|
||||
// UserBase is what the DB expects to see for write operations.
|
||||
type UserBase struct {
|
||||
ID int64 `json:"id,omitempty"`
|
||||
|
|
Reference in a new issue