37 lines
636 B
Go
37 lines
636 B
Go
package db
|
|
|
|
type Company struct {
|
|
ID int
|
|
UUID string
|
|
Name string
|
|
Email string
|
|
TaxId string
|
|
Password string
|
|
}
|
|
|
|
// InsertCompany inserts a new record into the Company table
|
|
func InsertCompany(company Company) (int, error) {
|
|
query := `
|
|
INSERT INTO Company (UUID, Name, Email, TaxId, Password)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
RETURNING id
|
|
`
|
|
|
|
stmt, err := db.Prepare(query)
|
|
if err != nil {
|
|
return -2, err
|
|
}
|
|
defer stmt.Close()
|
|
|
|
id := 0
|
|
err = stmt.QueryRow(
|
|
company.UUID, company.Name, company.Email, company.TaxId, company.Password,
|
|
).Scan(&id)
|
|
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|