Semaphore/db/Project.go

34 lines
747 B
Go
Raw Normal View History

2017-02-23 06:12:16 +01:00
package db
2016-04-02 14:40:07 +02:00
import (
"time"
)
// Project is the top level structure in Semaphore
2016-04-02 14:40:07 +02:00
type Project struct {
ID int `db:"id" json:"id"`
Name string `db:"name" json:"name" binding:"required"`
Created time.Time `db:"created" json:"created"`
Alert bool `db:"alert" json:"alert"`
AlertChat string `db:"alert_chat" json:"alert_chat"`
2016-04-02 14:40:07 +02:00
}
// CreateProject writes a project to the database
2016-04-02 14:40:07 +02:00
func (project *Project) CreateProject() error {
2016-06-02 20:26:51 +02:00
project.Created = time.Now()
2017-02-23 06:12:16 +01:00
res, err := Mysql.Exec("insert into project set name=?, created=?", project.Name, project.Created)
2016-04-02 14:40:07 +02:00
if err != nil {
return err
}
projectID, err := res.LastInsertId()
if err != nil {
return err
}
project.ID = int(projectID)
return nil
}