lxd/db/projects.mapper.go
func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error) {
	// Result slice.
	objects := make([]struct {
		Name  string
		Value string
	}, 0)

	// Check which filter criteria are active.
	criteria := map[string]interface{}{}
	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["Name"] != nil {
		stmt = c.stmt(projectUsedByRefByName)
		args = []interface{}{
			filter.Name,
		}
	} else {
		stmt = c.stmt(projectUsedByRef)
		args = []interface{}{}
	}

	// Dest function for scanning a row.
	dest := func(i int) []interface{} {
		objects = append(objects, struct {
			Name  string
			Value string
		}{})
		return []interface{}{
			&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 projects")
	}

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

	for _, object := range objects {
		item, ok := index[object.Name]
		if !ok {
			item = []string{}
		}

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

	return index, nil
}
func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error) {
	// Result slice.
	objects := make([]struct {
		Name  string
		Value string
	}, 0)

	// Check which filter criteria are active.
	criteria := map[string]interface{}{}
	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["Name"] != nil {
		stmt = c.stmt(projectUsedByRefByName)
		args = []interface{}{
			filter.Name,
		}
	} else {
		stmt = c.stmt(projectUsedByRef)
		args = []interface{}{}
	}

	// Dest function for scanning a row.
	dest := func(i int) []interface{} {
		objects = append(objects, struct {
			Name  string
			Value string
		}{})
		return []interface{}{
			&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 projects")
	}

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

	for _, object := range objects {
		item, ok := index[object.Name]
		if !ok {
			item = []string{}
		}

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

	return index, nil
}
// ProjectUsedByRef returns entities used by projects.