Example #1
0
func (repo *PgUserRepository) FindAll() ([]model.User, error) {
	rows, err := repo.manager.db.Query(`SELECT id, email, created, modified
        FROM user0`)

	if err != nil {
		return []model.User{}, err
	}

	var users []model.User
	for rows.Next() {
		user, err := marshal.User(rows)
		if err != nil {
			return []model.User{}, err
		}

		if users == nil {
			users = make([]model.User, 1, 10)
		}

		users = append(users, *user)
	}

	err = rows.Err()
	if err != nil {
		return []model.User{}, err
	}

	return users, nil
}
Example #2
0
func (repo *PgUserRepository) FindByEmail(email string) (*model.User, error) {
	row := repo.manager.db.QueryRow(`SELECT id, email, created, modified
        FROM user0
        WHERE email = $1`, email)

	user, err := marshal.User(row)

	return user, err
}
Example #3
0
func (repo *PgUserRepository) FindById(id int) (*model.User, error) {
	row := repo.manager.db.QueryRow(`SELECT id, email, created, modified
        FROM user0
        WHERE id = $1`, id)

	user, err := marshal.User(row)

	return user, err
}