lxd/db/projects.mapper.go
func (c *ClusterTx) ProjectCreate(object api.ProjectsPost) (int64, error) {
	// Check if a project with the same key exists.
	exists, err := c.ProjectExists(object.Name)
	if err != nil {
		return -1, errors.Wrap(err, "Failed to check for duplicates")
	}
	if exists {
		return -1, fmt.Errorf("This project already exists")
	}

	args := make([]interface{}, 2)

	// Populate the statement arguments.
	args[0] = object.Description
	args[1] = object.Name

	// Prepared statement to use.
	stmt := c.stmt(projectCreate)

	// Execute the statement.
	result, err := stmt.Exec(args...)
	if err != nil {
		return -1, errors.Wrap(err, "Failed to create project")
	}

	id, err := result.LastInsertId()
	if err != nil {
		return -1, errors.Wrap(err, "Failed to fetch project ID")
	}

	// Insert config reference.
	stmt = c.stmt(projectCreateConfigRef)
	for key, value := range object.Config {
		_, err := stmt.Exec(id, key, value)
		if err != nil {
			return -1, errors.Wrap(err, "Insert config for project")
		}
	}

	return id, nil
}
func (c *ClusterTx) ProjectCreate(object api.ProjectsPost) (int64, error) {
	// Check if a project with the same key exists.
	exists, err := c.ProjectExists(object.Name)
	if err != nil {
		return -1, errors.Wrap(err, "Failed to check for duplicates")
	}
	if exists {
		return -1, fmt.Errorf("This project already exists")
	}

	args := make([]interface{}, 2)

	// Populate the statement arguments.
	args[0] = object.Description
	args[1] = object.Name

	// Prepared statement to use.
	stmt := c.stmt(projectCreate)

	// Execute the statement.
	result, err := stmt.Exec(args...)
	if err != nil {
		return -1, errors.Wrap(err, "Failed to create project")
	}

	id, err := result.LastInsertId()
	if err != nil {
		return -1, errors.Wrap(err, "Failed to fetch project ID")
	}

	// Insert config reference.
	stmt = c.stmt(projectCreateConfigRef)
	for key, value := range object.Config {
		_, err := stmt.Exec(id, key, value)
		if err != nil {
			return -1, errors.Wrap(err, "Insert config for project")
		}
	}

	return id, nil
}
func ( c * ClusterTx ) ProjectCreate ( object api . ProjectsPost ) ( int64 , error ) { // Check if a project with the same key exists. exists , err := c . ProjectExists ( object . Name ) if err != nil { return - 1 , errors . Wrap ( err , " " ) } if exists { return - 1 , fmt . Errorf ( " " ) } args := make ( [ ] interface { } , 2 ) // Populate the statement arguments. args [ 0 ] = object . Description args [ 1 ] = object . Name // Prepared statement to use. stmt := c . stmt ( projectCreate ) // Execute the statement. result , err := stmt . Exec ( args ... ) if err != nil { return - 1 , errors . Wrap ( err , " " ) } id , err := result . LastInsertId ( ) if err != nil { return - 1 , errors . Wrap ( err , " " ) } // Insert config reference. stmt = c . stmt ( projectCreateConfigRef ) for key , value := range object . Config { _ , err := stmt . Exec ( id , key , value ) if err != nil { return - 1 , errors . Wrap ( err , " " ) } } return id , nil }
// ProjectCreate adds a new project to the database.
ProjectCreate adds a new project to the database .