lxd/db/profiles.mapper.go
func (c *ClusterTx) ProfileList(filter ProfileFilter) ([]Profile, error) {
	// Result slice.
	objects := make([]Profile, 0)

	// Check which filter criteria are active.
	criteria := map[string]interface{}{}
	if filter.Project != "" {
		criteria["Project"] = filter.Project
	}
	if filter.Name != "" {
		criteria["Name"] = filter.Name
	}

	// Pick the prepared statement and arguments to use based on active criteria.
	var stmt *sql.Stmt
	var args []interface{}

	if criteria["Project"] != nil && criteria["Name"] != nil {
		stmt = c.stmt(profileObjectsByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(profileObjectsByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(profileObjects)
		args = []interface{}{}
	}

	// Dest function for scanning a row.
	dest := func(i int) []interface{} {
		objects = append(objects, Profile{})
		return []interface{}{
			&objects[i].ID,
			&objects[i].Project,
			&objects[i].Name,
			&objects[i].Description,
		}
	}

	// Select.
	err := query.SelectObjects(stmt, dest, args...)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch profiles")
	}

	// Fill field Config.
	configObjects, err := c.ProfileConfigRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field Config")
	}

	for i := range objects {
		_, ok := configObjects[objects[i].Project]
		if !ok {
			subIndex := map[string]map[string]string{}
			configObjects[objects[i].Project] = subIndex
		}

		value := configObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = map[string]string{}
		}
		objects[i].Config = value
	}

	// Fill field Devices.
	devicesObjects, err := c.ProfileDevicesRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field Devices")
	}

	for i := range objects {
		_, ok := devicesObjects[objects[i].Project]
		if !ok {
			subIndex := map[string]map[string]map[string]string{}
			devicesObjects[objects[i].Project] = subIndex
		}

		value := devicesObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = map[string]map[string]string{}
		}
		objects[i].Devices = value
	}

	// Fill field UsedBy.
	usedByObjects, err := c.ProfileUsedByRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field UsedBy")
	}

	for i := range objects {
		_, ok := usedByObjects[objects[i].Project]
		if !ok {
			subIndex := map[string][]string{}
			usedByObjects[objects[i].Project] = subIndex
		}

		value := usedByObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = []string{}
		}
		objects[i].UsedBy = value
	}

	return objects, nil
}
func (c *ClusterTx) ProfileList(filter ProfileFilter) ([]Profile, error) {
	// Result slice.
	objects := make([]Profile, 0)

	// Check which filter criteria are active.
	criteria := map[string]interface{}{}
	if filter.Project != "" {
		criteria["Project"] = filter.Project
	}
	if filter.Name != "" {
		criteria["Name"] = filter.Name
	}

	// Pick the prepared statement and arguments to use based on active criteria.
	var stmt *sql.Stmt
	var args []interface{}

	if criteria["Project"] != nil && criteria["Name"] != nil {
		stmt = c.stmt(profileObjectsByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(profileObjectsByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(profileObjects)
		args = []interface{}{}
	}

	// Dest function for scanning a row.
	dest := func(i int) []interface{} {
		objects = append(objects, Profile{})
		return []interface{}{
			&objects[i].ID,
			&objects[i].Project,
			&objects[i].Name,
			&objects[i].Description,
		}
	}

	// Select.
	err := query.SelectObjects(stmt, dest, args...)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch profiles")
	}

	// Fill field Config.
	configObjects, err := c.ProfileConfigRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field Config")
	}

	for i := range objects {
		_, ok := configObjects[objects[i].Project]
		if !ok {
			subIndex := map[string]map[string]string{}
			configObjects[objects[i].Project] = subIndex
		}

		value := configObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = map[string]string{}
		}
		objects[i].Config = value
	}

	// Fill field Devices.
	devicesObjects, err := c.ProfileDevicesRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field Devices")
	}

	for i := range objects {
		_, ok := devicesObjects[objects[i].Project]
		if !ok {
			subIndex := map[string]map[string]map[string]string{}
			devicesObjects[objects[i].Project] = subIndex
		}

		value := devicesObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = map[string]map[string]string{}
		}
		objects[i].Devices = value
	}

	// Fill field UsedBy.
	usedByObjects, err := c.ProfileUsedByRef(filter)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to fetch field UsedBy")
	}

	for i := range objects {
		_, ok := usedByObjects[objects[i].Project]
		if !ok {
			subIndex := map[string][]string{}
			usedByObjects[objects[i].Project] = subIndex
		}

		value := usedByObjects[objects[i].Project][objects[i].Name]
		if value == nil {
			value = []string{}
		}
		objects[i].UsedBy = value
	}

	return objects, nil
}
func ( c * ClusterTx ) ProfileList ( filter ProfileFilter ) ( [ ] Profile , error ) { // Result slice. objects := make ( [ ] Profile , 0 ) // Check which filter criteria are active. criteria := map [ string ] interface { } { } if filter . Project != " " { criteria [ " " ] = filter . Project } if filter . Name != " " { criteria [ " " ] = filter . Name } // Pick the prepared statement and arguments to use based on active criteria. var stmt * sql . Stmt var args [ ] interface { } if criteria [ " " ] != nil && criteria [ " " ] != nil { stmt = c . stmt ( profileObjectsByProjectAndName ) args = [ ] interface { } { filter . Project , filter . Name , } } else if criteria [ " " ] != nil { stmt = c . stmt ( profileObjectsByProject ) args = [ ] interface { } { filter . Project , } } else { stmt = c . stmt ( profileObjects ) args = [ ] interface { } { } } // Dest function for scanning a row. dest := func ( i int ) [ ] interface { } { objects = append ( objects , Profile { } ) return [ ] interface { } { & objects [ i ] . ID , & objects [ i ] . Project , & objects [ i ] . Name , & objects [ i ] . Description , } } // Select. err := query . SelectObjects ( stmt , dest , args ... ) if err != nil { return nil , errors . Wrap ( err , " " ) } // Fill field Config. configObjects , err := c . ProfileConfigRef ( filter ) if err != nil { return nil , errors . Wrap ( err , " " ) } for i := range objects { _ , ok := configObjects [ objects [ i ] . Project ] if ! ok { subIndex := map [ string ] map [ string ] string { } configObjects [ objects [ i ] . Project ] = subIndex } value := configObjects [ objects [ i ] . Project ] [ objects [ i ] . Name ] if value == nil { value = map [ string ] string { } } objects [ i ] . Config = value } // Fill field Devices. devicesObjects , err := c . ProfileDevicesRef ( filter ) if err != nil { return nil , errors . Wrap ( err , " " ) } for i := range objects { _ , ok := devicesObjects [ objects [ i ] . Project ] if ! ok { subIndex := map [ string ] map [ string ] map [ string ] string { } devicesObjects [ objects [ i ] . Project ] = subIndex } value := devicesObjects [ objects [ i ] . Project ] [ objects [ i ] . Name ] if value == nil { value = map [ string ] map [ string ] string { } } objects [ i ] . Devices = value } // Fill field UsedBy. usedByObjects , err := c . ProfileUsedByRef ( filter ) if err != nil { return nil , errors . Wrap ( err , " " ) } for i := range objects { _ , ok := usedByObjects [ objects [ i ] . Project ] if ! ok { subIndex := map [ string ] [ ] string { } usedByObjects [ objects [ i ] . Project ] = subIndex } value := usedByObjects [ objects [ i ] . Project ] [ objects [ i ] . Name ] if value == nil { value = [ ] string { } } objects [ i ] . UsedBy = value } return objects , nil }
// ProfileList returns all available profiles.
ProfileList returns all available profiles .