Use “SelectOne” everywhere.
This commit is contained in:
		
							parent
							
								
									5d2b644145
								
							
						
					
					
						commit
						61c24fc843
					
				
					 8 changed files with 32 additions and 32 deletions
				
			
		|  | @ -15,14 +15,14 @@ type characteristicTypesStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *characteristicTypesStore) Get(id int64) (*models.CharacteristicType, error) { | func (s *characteristicTypesStore) Get(id int64) (*models.CharacteristicType, error) { | ||||||
| 	var characteristic_type []*models.CharacteristicType | 	var characteristic_type models.CharacteristicType | ||||||
| 	if err := s.dbh.Select(&characteristic_type, `SELECT * FROM characteristic_types WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&characteristic_type, `SELECT * FROM characteristic_types WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(characteristic_type) == 0 { | 	if &characteristic_type == nil { | ||||||
| 		return nil, models.ErrCharacteristicTypeNotFound | 		return nil, models.ErrCharacteristicTypeNotFound | ||||||
| 	} | 	} | ||||||
| 	return characteristic_type[0], nil | 	return &characteristic_type, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *characteristicTypesStore) Create(characteristic_type *models.CharacteristicType) (bool, error) { | func (s *characteristicTypesStore) Create(characteristic_type *models.CharacteristicType) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -15,14 +15,14 @@ type characteristicsStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *characteristicsStore) Get(id int64) (*models.Characteristic, error) { | func (s *characteristicsStore) Get(id int64) (*models.Characteristic, error) { | ||||||
| 	var characteristic []*models.Characteristic | 	var characteristic models.Characteristic | ||||||
| 	if err := s.dbh.Select(&characteristic, `SELECT * FROM characteristics WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&characteristic, `SELECT * FROM characteristics WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(characteristic) == 0 { | 	if &characteristic == nil { | ||||||
| 		return nil, models.ErrCharacteristicNotFound | 		return nil, models.ErrCharacteristicNotFound | ||||||
| 	} | 	} | ||||||
| 	return characteristic[0], nil | 	return &characteristic, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *characteristicsStore) Create(characteristic *models.Characteristic) (bool, error) { | func (s *characteristicsStore) Create(characteristic *models.Characteristic) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -17,14 +17,14 @@ type measurementsStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *measurementsStore) Get(id int64) (*models.Measurement, error) { | func (s *measurementsStore) Get(id int64) (*models.Measurement, error) { | ||||||
| 	var measurement []*models.Measurement | 	var measurement models.Measurement | ||||||
| 	if err := s.dbh.Select(&measurement, `SELECT * FROM measurements WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&measurement, `SELECT * FROM measurements WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(measurement) == 0 { | 	if &measurement == nil { | ||||||
| 		return nil, models.ErrMeasurementNotFound | 		return nil, models.ErrMeasurementNotFound | ||||||
| 	} | 	} | ||||||
| 	return measurement[0], nil | 	return &measurement, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *measurementsStore) Create(measurement *models.Measurement) (bool, error) { | func (s *measurementsStore) Create(measurement *models.Measurement) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -16,14 +16,14 @@ type speciesStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *speciesStore) Get(id int64) (*models.Species, error) { | func (s *speciesStore) Get(id int64) (*models.Species, error) { | ||||||
| 	var species []*models.Species | 	var species models.Species | ||||||
| 	if err := s.dbh.Select(&species, `SELECT * FROM species WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&species, `SELECT * FROM species WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(species) == 0 { | 	if &species == nil { | ||||||
| 		return nil, models.ErrSpeciesNotFound | 		return nil, models.ErrSpeciesNotFound | ||||||
| 	} | 	} | ||||||
| 	return species[0], nil | 	return &species, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *speciesStore) Create(species *models.Species) (bool, error) { | func (s *speciesStore) Create(species *models.Species) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -17,14 +17,14 @@ type strainsStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *strainsStore) Get(id int64) (*models.Strain, error) { | func (s *strainsStore) Get(id int64) (*models.Strain, error) { | ||||||
| 	var strain []*models.Strain | 	var strain models.Strain | ||||||
| 	if err := s.dbh.Select(&strain, `SELECT * FROM strains WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&strain, `SELECT * FROM strains WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(strain) == 0 { | 	if &strain == nil { | ||||||
| 		return nil, models.ErrStrainNotFound | 		return nil, models.ErrStrainNotFound | ||||||
| 	} | 	} | ||||||
| 	return strain[0], nil | 	return &strain, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *strainsStore) Create(strain *models.Strain) (bool, error) { | func (s *strainsStore) Create(strain *models.Strain) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -15,14 +15,14 @@ type textMeasurementTypesStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *textMeasurementTypesStore) Get(id int64) (*models.TextMeasurementType, error) { | func (s *textMeasurementTypesStore) Get(id int64) (*models.TextMeasurementType, error) { | ||||||
| 	var text_measurement_type []*models.TextMeasurementType | 	var text_measurement_type models.TextMeasurementType | ||||||
| 	if err := s.dbh.Select(&text_measurement_type, `SELECT * FROM text_measurement_types WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&text_measurement_type, `SELECT * FROM text_measurement_types WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(text_measurement_type) == 0 { | 	if &text_measurement_type == nil { | ||||||
| 		return nil, models.ErrTextMeasurementTypeNotFound | 		return nil, models.ErrTextMeasurementTypeNotFound | ||||||
| 	} | 	} | ||||||
| 	return text_measurement_type[0], nil | 	return &text_measurement_type, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *textMeasurementTypesStore) Create(text_measurement_type *models.TextMeasurementType) (bool, error) { | func (s *textMeasurementTypesStore) Create(text_measurement_type *models.TextMeasurementType) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -15,14 +15,14 @@ type unitTypesStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *unitTypesStore) Get(id int64) (*models.UnitType, error) { | func (s *unitTypesStore) Get(id int64) (*models.UnitType, error) { | ||||||
| 	var unit_type []*models.UnitType | 	var unit_type models.UnitType | ||||||
| 	if err := s.dbh.Select(&unit_type, `SELECT * FROM unit_types WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&unit_type, `SELECT * FROM unit_types WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(unit_type) == 0 { | 	if &unit_type == nil { | ||||||
| 		return nil, models.ErrUnitTypeNotFound | 		return nil, models.ErrUnitTypeNotFound | ||||||
| 	} | 	} | ||||||
| 	return unit_type[0], nil | 	return &unit_type, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *unitTypesStore) Create(unit_type *models.UnitType) (bool, error) { | func (s *unitTypesStore) Create(unit_type *models.UnitType) (bool, error) { | ||||||
|  |  | ||||||
|  | @ -17,14 +17,14 @@ type usersStore struct { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *usersStore) Get(id int64) (*models.User, error) { | func (s *usersStore) Get(id int64) (*models.User, error) { | ||||||
| 	var users []*models.User | 	var user models.User | ||||||
| 	if err := s.dbh.Select(&users, `SELECT * FROM users WHERE id=$1;`, id); err != nil { | 	if err := s.dbh.SelectOne(&user, `SELECT * FROM users WHERE id=$1;`, id); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	if len(users) == 0 { | 	if &user == nil { | ||||||
| 		return nil, models.ErrUserNotFound | 		return nil, models.ErrUserNotFound | ||||||
| 	} | 	} | ||||||
| 	return users[0], nil | 	return &user, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (s *usersStore) Create(user *models.User) (bool, error) { | func (s *usersStore) Create(user *models.User) (bool, error) { | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon