lxd/db/profiles.mapper.go
func (c *ClusterTx) ProfileUsedByRef(filter ProfileFilter) (map[string]map[string][]string, error) {
	// Result slice.
	objects := make([]struct {
		Project string
		Name    string
		Value   string
	}, 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(profileUsedByRefByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(profileUsedByRefByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(profileUsedByRef)
		args = []interface{}{}
	}

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

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

	// Build index by primary name.
	index := map[string]map[string][]string{}

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

		item, ok := index[object.Project][object.Name]
		if !ok {
			item = []string{}
		}

		index[object.Project][object.Name] = append(item, object.Value)
	}

	return index, nil
}
func (c *ClusterTx) ProfileUsedByRef(filter ProfileFilter) (map[string]map[string][]string, error) {
	// Result slice.
	objects := make([]struct {
		Project string
		Name    string
		Value   string
	}, 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(profileUsedByRefByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(profileUsedByRefByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(profileUsedByRef)
		args = []interface{}{}
	}

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

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

	// Build index by primary name.
	index := map[string]map[string][]string{}

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

		item, ok := index[object.Project][object.Name]
		if !ok {
			item = []string{}
		}

		index[object.Project][object.Name] = append(item, object.Value)
	}

	return index, nil
}
func ( c * ClusterTx ) ProfileUsedByRef ( filter ProfileFilter ) ( map [ string ] map [ string ] [ ] string , error ) { // Result slice. objects := make ( [ ] struct { Project string Name string Value string } , 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 ( profileUsedByRefByProjectAndName ) args = [ ] interface { } { filter . Project , filter . Name , } } else if criteria [ " " ] != nil { stmt = c . stmt ( profileUsedByRefByProject ) args = [ ] interface { } { filter . Project , } } else { stmt = c . stmt ( profileUsedByRef ) args = [ ] interface { } { } } // Dest function for scanning a row. dest := func ( i int ) [ ] interface { } { objects = append ( objects , struct { Project string Name string Value string } { } ) return [ ] interface { } { & objects [ i ] . Project , & objects [ i ] . Name , & objects [ i ] . Value , } } // Select. err := query . SelectObjects ( stmt , dest , args ... ) if err != nil { return nil , errors . Wrap ( err , " " ) } // Build index by primary name. index := map [ string ] map [ string ] [ ] string { } for _ , object := range objects { _ , ok := index [ object . Project ] if ! ok { subIndex := map [ string ] [ ] string { } index [ object . Project ] = subIndex } item , ok := index [ object . Project ] [ object . Name ] if ! ok { item = [ ] string { } } index [ object . Project ] [ object . Name ] = append ( item , object . Value ) } return index , nil }
// ProfileUsedByRef returns entities used by profiles.
ProfileUsedByRef returns entities used by profiles .