Created
February 9, 2021 06:23
-
-
Save vedashree29296/0063d5f3b0ad8be48c241992b59f45cb to your computer and use it in GitHub Desktop.
Create a category with no return value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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