Skip to content

Commit

Permalink
fix: reverted unnecessary breaking change in generator (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp authored Jan 24, 2023
1 parent 46d09d3 commit feab1b0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ type {{.Model}} struct {
{{.Fields}}
}
func ({{.M}} {{.Model}}) TableName() string {
func ({{.M}} *{{.Model}}) TableName() string {
return {{.Model}}TableName
}
type Update{{.Model}} struct {
{{.UpdaterFields}}
}
func ({{.M}} Update{{.Model}}) UpdateTableName() string {
func ({{.M}} *Update{{.Model}}) UpdateTableName() string {
return {{.Model}}TableName
}
Expand Down
4 changes: 2 additions & 2 deletions model/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Fields struct {
JsonNullField null.JSON `exql:"column:json_null_field;type:json" json:"json_null_field"`
}

func (f Fields) TableName() string {
func (f *Fields) TableName() string {
return FieldsTableName
}

Expand Down Expand Up @@ -125,7 +125,7 @@ type UpdateFields struct {
JsonNullField *null.JSON `exql:"column:json_null_field;type:json" json:"json_null_field"`
}

func (f UpdateFields) UpdateTableName() string {
func (f *UpdateFields) UpdateTableName() string {
return FieldsTableName
}

Expand Down
4 changes: 2 additions & 2 deletions model/group_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type GroupUsers struct {
GroupId int64 `exql:"column:group_id;type:int(11);not null" json:"group_id"`
}

func (g GroupUsers) TableName() string {
func (g *GroupUsers) TableName() string {
return GroupUsersTableName
}

Expand All @@ -17,7 +17,7 @@ type UpdateGroupUsers struct {
GroupId *int64 `exql:"column:group_id;type:int(11);not null" json:"group_id"`
}

func (g UpdateGroupUsers) UpdateTableName() string {
func (g *UpdateGroupUsers) UpdateTableName() string {
return GroupUsersTableName
}

Expand Down
4 changes: 2 additions & 2 deletions model/user_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type UserGroups struct {
Name string `exql:"column:name;type:varchar(255);not null" json:"name"`
}

func (u UserGroups) TableName() string {
func (u *UserGroups) TableName() string {
return UserGroupsTableName
}

Expand All @@ -15,7 +15,7 @@ type UpdateUserGroups struct {
Name *string `exql:"column:name;type:varchar(255);not null" json:"name"`
}

func (u UpdateUserGroups) UpdateTableName() string {
func (u *UpdateUserGroups) UpdateTableName() string {
return UserGroupsTableName
}

Expand Down
4 changes: 2 additions & 2 deletions model/user_login_histories.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type UserLoginHistories struct {
CreatedAt time.Time `exql:"column:created_at;type:datetime;primary;not null" json:"created_at"`
}

func (u UserLoginHistories) TableName() string {
func (u *UserLoginHistories) TableName() string {
return UserLoginHistoriesTableName
}

Expand All @@ -19,7 +19,7 @@ type UpdateUserLoginHistories struct {
CreatedAt *time.Time `exql:"column:created_at;type:datetime;primary;not null" json:"created_at"`
}

func (u UpdateUserLoginHistories) UpdateTableName() string {
func (u *UpdateUserLoginHistories) UpdateTableName() string {
return UserLoginHistoriesTableName
}

Expand Down
4 changes: 2 additions & 2 deletions model/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Users struct {
LastName null.String `exql:"column:last_name;type:varchar(255)" json:"last_name"`
}

func (u Users) TableName() string {
func (u *Users) TableName() string {
return UsersTableName
}

Expand All @@ -19,7 +19,7 @@ type UpdateUsers struct {
LastName *null.String `exql:"column:last_name;type:varchar(255)" json:"last_name"`
}

func (u UpdateUsers) UpdateTableName() string {
func (u *UpdateUsers) UpdateTableName() string {
return UsersTableName
}

Expand Down
10 changes: 1 addition & 9 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestQueryForBulkInsert(t *testing.T) {
}, args)
})
t.Run("error if args empty", func(t *testing.T) {
q, err := exql.QueryForBulkInsert[model.Users]()
q, err := exql.QueryForBulkInsert[*model.Users]()
assert.Nil(t, q)
assert.EqualError(t, err, "empty list")
})
Expand Down Expand Up @@ -95,10 +95,6 @@ func TestAggregateModelMetadata(t *testing.T) {
t.Run("should error if dest is nil", func(t *testing.T) {
assertInvalid(t, nil, "pointer is nil")
})
t.Run("should error if dest is not pointer", func(t *testing.T) {
user := model.Users{}
assertInvalid(t, user, "object must be pointer of struct")
})
t.Run("should error if TableName() doesn't return string", func(t *testing.T) {
assertInvalid(t, &testmodel.BadTableName{}, "empty table name")
})
Expand Down Expand Up @@ -139,10 +135,6 @@ func TestQueryForUpdateModel(t *testing.T) {
_, err := exql.QueryForUpdateModel(nil, nil)
assert.EqualError(t, err, "pointer is nil")
})
t.Run("should error if not pointer", func(t *testing.T) {
_, err := exql.QueryForUpdateModel(model.UpdateUsers{}, nil)
assert.EqualError(t, err, "must be pointer of struct")
})
t.Run("should error if has invalid tag", func(t *testing.T) {
_, err := exql.QueryForUpdateModel(&upSampleInvalidTag{}, nil)
assert.EqualError(t, err, "invalid tag format")
Expand Down
7 changes: 6 additions & 1 deletion tool/modelgen/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"log"

_ "github.com/go-sql-driver/mysql"
"github.com/loilo-inc/exql/v2"
)
Expand All @@ -10,7 +12,10 @@ func main() {
Url: "root:@tcp(127.0.0.1:13326)/exql?charset=utf8mb4&parseTime=True&loc=Local",
})
g := exql.NewGenerator(db.DB())
g.Generate(&exql.GenerateOptions{
err := g.Generate(&exql.GenerateOptions{
OutDir: "model",
})
if err != nil {
log.Fatal(err)
}
}

0 comments on commit feab1b0

Please sign in to comment.