most of add

This commit is contained in:
Dan Ballard 2015-07-07 22:49:11 -07:00
parent a860c3ad70
commit 35406174a2
1 changed files with 13 additions and 0 deletions

View File

@ -48,6 +48,19 @@ func LoadCategories(db *sql.DB) {
}
}
func Add(db *sql.DB, name string, parent int) error {
var err error
if parent < 0 {
err := db.Exec("INSERT INTO categories (name) VALUE ($1)", name)
} else {
err := db.Exec("INSERT INTO categories (name, parent_id) VALUE ($1, $2)", name, parent)
}
if err != nil {
fmt.Println("Categories DB Error Add(): " , err)
}
return err
}
func (category *Category) ChangeParent(db *sql.DB, parent *Category) error {
var err error
if parent == nil {