Skip to content

Instantly share code, notes, and snippets.

@vedashree29296
Created February 9, 2021 06:23
Show Gist options
  • Save vedashree29296/0063d5f3b0ad8be48c241992b59f45cb to your computer and use it in GitHub Desktop.
Save vedashree29296/0063d5f3b0ad8be48c241992b59f45cb to your computer and use it in GitHub Desktop.
Create a category with no return value
//CreateCategory : create a new Category in DB
func (c *Category) CreateCategory() error {
// prepare the query
stmt, err := client.DbClient.Prepare("INSERT INTO category (category_name) values ($1);")
if err != nil {
return err
}
//closing the statement to prevent memory leaks
defer stmt.Close()
//execute the query
_, err = stmt.Exec(c.ID)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment