예제 #1
0
func GetUserByName(txn *gorp.Transaction, name string) (*models.User, error) {
	qrows := make([]models.User, 0)

	_, err := txn.Select(&qrows, SQL_USER_BYNAME, map[string]interface{}{
		"name": name,
	})
	if err != nil {
		return nil, err
	}
	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
예제 #2
0
func GetDeviceBySerial(txn *gorp.Transaction, serial string) (*models.Device, error) {
	qrows := make([]models.Device, 0)

	_, err := txn.Select(&qrows, SQL_DEVICE_BYSERIAL, map[string]interface{}{
		"serial": serial,
	})
	if err != nil {
		return nil, err
	}

	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
예제 #3
0
func GetRowByUnique(
	txn *gorp.Transaction,
	query string,
	qrows interface{},
	unique map[string]interface{}) (interface{}, error) {

	_, err := txn.Select(qrows, query, unique)
	if err != nil {
		return nil, err
	}

	rowsSlice := MakeGenericSlice(qrows)
	if len(rowsSlice) != 1 {
		return nil, nil
	}

	return rowsSlice[0], nil
}
예제 #4
0
func GetLoglevelByName(
	txn *gorp.Transaction,
	name string) (*models.LogLevel, error) {
	qrows := make([]models.LogLevel, 0)

	_, err := txn.Select(&qrows, SQL_LOGLEVEL_BYDESC, map[string]interface{}{
		"name": name,
	})
	if err != nil {
		return nil, err
	}

	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
예제 #5
0
func GetCategoryByDescription(
	txn *gorp.Transaction,
	desc string) (*models.Category, error) {

	qrows := make([]models.Category, 0)

	_, err := txn.Select(&qrows, SQL_CATEGORY_BYNAME, map[string]interface{}{
		"desc": desc,
	})
	if err != nil {
		return nil, err
	}
	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}
예제 #6
0
func GetLogtypeByNames(
	txn *gorp.Transaction,
	level1, level2 string) (*models.LogType, error) {
	qrows := make([]models.LogType, 0)

	_, err := txn.Select(&qrows, SQL_LOGTYPE_BYNAME, map[string]interface{}{
		"level1": level1,
		"level2": level2,
	})
	if err != nil {
		return nil, err
	}

	if len(qrows) != 1 {
		return nil, nil
	}

	return &qrows[0], nil
}