lxd/db/projects.mapper.go
func (c *ClusterTx) ProjectList(filter ProjectFilter) ([]api.Project, error) {
	// Result slice.
	objects := make([]api.Project, 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(projectObjectsByName)
		args = []interface{}{
			filter.Name,
		}
	} else {
		stmt = c.stmt(projectObjects)
		args = []interface{}{}
	}

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

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

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

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

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

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

	return objects, nil
}
func (c *ClusterTx) ProjectList(filter ProjectFilter) ([]api.Project, error) {
	// Result slice.
	objects := make([]api.Project, 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(projectObjectsByName)
		args = []interface{}{
			filter.Name,
		}
	} else {
		stmt = c.stmt(projectObjects)
		args = []interface{}{}
	}

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

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

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

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

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

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

	return objects, nil
}
func ( c * ClusterTx ) ProjectList ( filter ProjectFilter ) ( [ ] api . Project , error ) { // Result slice. objects := make ( [ ] api . Project , 0 ) // Check which filter criteria are active. criteria := map [ string ] interface { } { } 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 { stmt = c . stmt ( projectObjectsByName ) args = [ ] interface { } { filter . Name , } } else { stmt = c . stmt ( projectObjects ) args = [ ] interface { } { } } // Dest function for scanning a row. dest := func ( i int ) [ ] interface { } { objects = append ( objects , api . Project { } ) return [ ] interface { } { & objects [ i ] . Description , & objects [ i ] . Name , } } // Select. err := query . SelectObjects ( stmt , dest , args ... ) if err != nil { return nil , errors . Wrap ( err , " " ) } // Fill field Config. configObjects , err := c . ProjectConfigRef ( filter ) if err != nil { return nil , errors . Wrap ( err , " " ) } for i := range objects { value := configObjects [ objects [ i ] . Name ] if value == nil { value = map [ string ] string { } } objects [ i ] . Config = value } // Fill field UsedBy. usedByObjects , err := c . ProjectUsedByRef ( filter ) if err != nil { return nil , errors . Wrap ( err , " " ) } for i := range objects { value := usedByObjects [ objects [ i ] . Name ] if value == nil { value = [ ] string { } } objects [ i ] . UsedBy = value } return objects , nil }
// ProjectList returns all available projects.
ProjectList returns all available projects .