Skip to content

Commit

Permalink
Merge pull request #27 from twharmon/method-names
Browse files Browse the repository at this point in the history
Method names
  • Loading branch information
twharmon authored Jan 8, 2020
2 parents 1b85112 + 88a420c commit 099dc21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (db *DB) Insert(obj interface{}) (sql.Result, error) {
return db.db.Exec(m.getInsertQuery(v), m.getArgs(v)...)
}

// Save .
func (db *DB) Save(obj interface{}) (sql.Result, error) {
// Update .
func (db *DB) Update(obj interface{}) (sql.Result, error) {
m, err := getModelOf(obj)
if err != nil {
return nil, err
Expand Down Expand Up @@ -80,8 +80,8 @@ func (db *DB) Select(fields ...string) *SelectQuery {
return sq
}

// Update .
func (db *DB) Update(table string) *UpdateQuery {
// ManualUpdate .
func (db *DB) ManualUpdate(table string) *UpdateQuery {
uq := new(UpdateQuery)
uq.db = db
uq.table = table
Expand All @@ -97,8 +97,8 @@ func (db *DB) Count(table string, count string) *CountQuery {
return cq
}

// Delete .
func (db *DB) Delete(table string) *DeleteQuery {
// ManualDelete .
func (db *DB) ManualDelete(table string) *DeleteQuery {
dq := new(DeleteQuery)
dq.db = db
dq.table = table
Expand Down
12 changes: 6 additions & 6 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestInsert(t *testing.T) {
}
}

func TestSave(t *testing.T) {
func TestUpdate(t *testing.T) {
user := &User{
ID: 5,
Role: "admin",
Expand All @@ -36,7 +36,7 @@ func TestSave(t *testing.T) {

mock.ExpectExec(`^update user set role = \?, email = \?, active = \? where id = \?$`).WithArgs(user.Role, user.Email, user.Active, user.ID).WillReturnResult(sqlmock.NewResult(1, 1))

if _, err := DBConn.Save(user); err != nil {
if _, err := DBConn.Update(user); err != nil {
t.Errorf("error was not expected while inserting: %s", err)
return
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestInsertAllTypesNull(t *testing.T) {
}
}

func TestUpdate(t *testing.T) {
func TestManualUpdate(t *testing.T) {
user := &User{
ID: 5,
Role: "admin",
Expand All @@ -110,7 +110,7 @@ func TestUpdate(t *testing.T) {

mock.ExpectExec(`^update user set role = \?, email = \?, active = \? where id = \?$`).WithArgs(user.Role, user.Email, user.Active, user.ID).WillReturnResult(sqlmock.NewResult(1, 1))

q := DBConn.Update("user")
q := DBConn.ManualUpdate("user")
q.Set("role = ?", user.Role)
q.Set("email = ?", user.Email)
q.Set("active = ?", user.Active)
Expand All @@ -126,10 +126,10 @@ func TestUpdate(t *testing.T) {
}
}

func TestDelete(t *testing.T) {
func TestManualDelete(t *testing.T) {
mock.ExpectExec(`^delete from user where id = \?$`).WithArgs(1).WillReturnResult(sqlmock.NewResult(0, 1))

q := DBConn.Delete("user")
q := DBConn.ManualDelete("user")
q.Where("id = ?", 1)

if _, err := q.Exec(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

// User .
type User struct {
Email string `json:"email" size:"255"`
ID uint `json:"id" gosql:"primary"`
Email string `json:"email" size:"255"`
Password string `json:"password" size:"100"`
IsAdmin bool `json:"isAdmin"`
IsActive bool `json:"isActive"`
Expand Down
2 changes: 1 addition & 1 deletion model.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (m *model) getFieldIndexByName(name string) int {
}

func (m *model) getArgs(v reflect.Value) []interface{} {
var args []interface{} // TODO: make()
var args []interface{}
for i := 0; i < m.fieldCount; i++ {
f := v.Field(i)
if m.primaryFieldIndex == i && f.IsZero() {
Expand Down

0 comments on commit 099dc21

Please sign in to comment.