Setting created & update cols.
This commit is contained in:
parent
f48ee87ccd
commit
bedddfdec1
4 changed files with 26 additions and 2 deletions
|
@ -2,6 +2,7 @@ package datastore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/thermokarst/bactdb/models"
|
"github.com/thermokarst/bactdb/models"
|
||||||
)
|
)
|
||||||
|
@ -26,6 +27,9 @@ func (s *generaStore) Get(id int64) (*models.Genus, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *generaStore) Create(genus *models.Genus) (bool, error) {
|
func (s *generaStore) Create(genus *models.Genus) (bool, error) {
|
||||||
|
currentTime := time.Now()
|
||||||
|
genus.CreatedAt = currentTime
|
||||||
|
genus.UpdatedAt = currentTime
|
||||||
if err := s.dbh.Insert(genus); err != nil {
|
if err := s.dbh.Insert(genus); err != nil {
|
||||||
if strings.Contains(err.Error(), `violates unique constraint "genus_idx"`) {
|
if strings.Contains(err.Error(), `violates unique constraint "genus_idx"`) {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -56,6 +60,7 @@ func (s *generaStore) Update(id int64, genus *models.Genus) (bool, error) {
|
||||||
return false, models.ErrGenusNotFound
|
return false, models.ErrGenusNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
genus.UpdatedAt = time.Now()
|
||||||
changed, err := s.dbh.Update(genus)
|
changed, err := s.dbh.Update(genus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package datastore
|
package datastore
|
||||||
|
|
||||||
import "github.com/thermokarst/bactdb/models"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/thermokarst/bactdb/models"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DB.AddTableWithName(models.Species{}, "species").SetKeys(true, "Id")
|
DB.AddTableWithName(models.Species{}, "species").SetKeys(true, "Id")
|
||||||
|
@ -22,6 +26,9 @@ func (s *speciesStore) Get(id int64) (*models.Species, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *speciesStore) Create(species *models.Species) (bool, error) {
|
func (s *speciesStore) Create(species *models.Species) (bool, error) {
|
||||||
|
currentTime := time.Now()
|
||||||
|
species.CreatedAt = currentTime
|
||||||
|
species.UpdatedAt = currentTime
|
||||||
if err := s.dbh.Insert(species); err != nil {
|
if err := s.dbh.Insert(species); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -50,6 +57,7 @@ func (s *speciesStore) Update(id int64, species *models.Species) (bool, error) {
|
||||||
return false, models.ErrSpeciesNotFound
|
return false, models.ErrSpeciesNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
species.UpdatedAt = time.Now()
|
||||||
changed, err := s.dbh.Update(species)
|
changed, err := s.dbh.Update(species)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package datastore
|
package datastore
|
||||||
|
|
||||||
import "github.com/thermokarst/bactdb/models"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/thermokarst/bactdb/models"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DB.AddTableWithName(models.Strain{}, "strains").SetKeys(true, "Id")
|
DB.AddTableWithName(models.Strain{}, "strains").SetKeys(true, "Id")
|
||||||
|
@ -22,6 +26,9 @@ func (s *strainsStore) Get(id int64) (*models.Strain, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *strainsStore) Create(strain *models.Strain) (bool, error) {
|
func (s *strainsStore) Create(strain *models.Strain) (bool, error) {
|
||||||
|
currentTime := time.Now()
|
||||||
|
strain.CreatedAt = currentTime
|
||||||
|
strain.UpdatedAt = currentTime
|
||||||
if err := s.dbh.Insert(strain); err != nil {
|
if err := s.dbh.Insert(strain); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -50,6 +57,7 @@ func (s *strainsStore) Update(id int64, strain *models.Strain) (bool, error) {
|
||||||
return false, models.ErrStrainNotFound
|
return false, models.ErrStrainNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strain.UpdatedAt = time.Now()
|
||||||
changed, err := s.dbh.Update(strain)
|
changed, err := s.dbh.Update(strain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -32,6 +32,9 @@ func (s *usersStore) Get(id int64) (*models.User, error) {
|
||||||
func (s *usersStore) Create(user *models.User) (bool, error) {
|
func (s *usersStore) Create(user *models.User) (bool, error) {
|
||||||
retries := 3
|
retries := 3
|
||||||
var wantRetry bool
|
var wantRetry bool
|
||||||
|
currentTime := time.Now()
|
||||||
|
user.CreatedAt = currentTime
|
||||||
|
user.UpdatedAt = currentTime
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
retries--
|
retries--
|
||||||
|
|
Reference in a new issue