compnay select
This commit is contained in:
21
app/lib/company/company.go
Normal file
21
app/lib/company/company.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package company
|
||||
|
||||
import (
|
||||
"bordrobot/lib/db"
|
||||
)
|
||||
|
||||
type Company struct {
|
||||
Name string `db:"name"`
|
||||
MemberNumber string `db:"member_number"`
|
||||
Username string `db:"username"`
|
||||
Password string `db:"password"`
|
||||
}
|
||||
|
||||
func (c *Company) Create() error {
|
||||
sq := `
|
||||
insert into company (name, member_number, username, password)
|
||||
VALUES (:name, :member_number, :username, :password)
|
||||
`
|
||||
_, err := db.DB.NamedExec(sq, &c)
|
||||
return err
|
||||
}
|
||||
27
app/lib/company/company_test.go
Normal file
27
app/lib/company/company_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package company
|
||||
|
||||
import (
|
||||
"bordrobot/lib/db"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCompany_Create(t *testing.T) {
|
||||
err := db.InitDB("../..")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
c := &Company{
|
||||
Name: "Deneme Firması",
|
||||
MemberNumber: "1234",
|
||||
Username: "u1",
|
||||
Password: "p1",
|
||||
}
|
||||
|
||||
err = c.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
db.DB.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user