Пример #1
0
func (repo *MockUserRepository) Create(user *model.User) error {
	err := user.Validate(repo)
	if err != nil {
		return err
	}

	id := repo.lastId + 1
	user.Id = id
	repo.lastId = id

	t := time.Now()
	user.Created = t
	user.Modified = t

	repo.mocks[id] = user

	return nil
}
Пример #2
0
func (repo *PgUserRepository) Create(user *model.User) error {
	err := user.Validate(repo)
	if err != nil {
		return err
	}

	t := time.Now()

	var id int
	err = repo.manager.db.QueryRow(`INSERT INTO user0(email, created, modified) 
	    VALUES($1, $2, $3) RETURNING id`,
		user.Email, t, t).Scan(&id)

	if err != nil {
		return err
	}

	user.Id = id
	user.Created = t
	user.Modified = t

	return nil
}