lxd/db/containers.mapper.go
func (c *ClusterTx) ContainerConfigRef(filter ContainerFilter) (map[string]map[string]map[string]string, error) {
	// Result slice.
	objects := make([]struct {
		Project string
		Name    string
		Key     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
	}
	if filter.Parent != "" {
		criteria["Parent"] = filter.Parent
	}

	// 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(containerConfigRefByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil && criteria["Node"] != nil {
		stmt = c.stmt(containerConfigRefByProjectAndNode)
		args = []interface{}{
			filter.Project,
			filter.Node,
		}
	} else if criteria["Node"] != nil {
		stmt = c.stmt(containerConfigRefByNode)
		args = []interface{}{
			filter.Node,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(containerConfigRefByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(containerConfigRef)
		args = []interface{}{}
	}

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

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

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

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

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

		index[object.Project][object.Name] = item
		item[object.Key] = object.Value
	}

	return index, nil
}
func (c *ClusterTx) ContainerConfigRef(filter ContainerFilter) (map[string]map[string]map[string]string, error) {
	// Result slice.
	objects := make([]struct {
		Project string
		Name    string
		Key     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
	}
	if filter.Parent != "" {
		criteria["Parent"] = filter.Parent
	}

	// 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(containerConfigRefByProjectAndName)
		args = []interface{}{
			filter.Project,
			filter.Name,
		}
	} else if criteria["Project"] != nil && criteria["Node"] != nil {
		stmt = c.stmt(containerConfigRefByProjectAndNode)
		args = []interface{}{
			filter.Project,
			filter.Node,
		}
	} else if criteria["Node"] != nil {
		stmt = c.stmt(containerConfigRefByNode)
		args = []interface{}{
			filter.Node,
		}
	} else if criteria["Project"] != nil {
		stmt = c.stmt(containerConfigRefByProject)
		args = []interface{}{
			filter.Project,
		}
	} else {
		stmt = c.stmt(containerConfigRef)
		args = []interface{}{}
	}

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

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

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

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

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

		index[object.Project][object.Name] = item
		item[object.Key] = object.Value
	}

	return index, nil
}
// ContainerConfigRef returns entities used by containers.