Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default TableName of NewAdapterByDB() #51

Merged
merged 3 commits into from
Sep 21, 2020
Merged

Conversation

miaolz123
Copy link
Contributor

No description provided.

Signed-off-by: miaolz123 <miaolizhao@126.com>
Signed-off-by: miaolz123 <miaolizhao@126.com>
Signed-off-by: miaolz123 <miaolizhao@126.com>
@miaolz123
Copy link
Contributor Author

from #50

@coveralls
Copy link

Coverage Status

Coverage increased (+1.8%) to 61.667% when pulling 34590b6 on miaolz123:master into 9cc32f0 on casbin:master.

@hsluoyz
Copy link
Member

hsluoyz commented Sep 17, 2020

@nodece @GopherJ @00LT00 please review.

Copy link
Member

@00LT00 00LT00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hsluoyz hsluoyz changed the title add default TtableName of NewAdapterByDB() add default TableName of NewAdapterByDB() Sep 17, 2020
@@ -184,8 +184,8 @@ func openDBConnection(driverName, dataSourceName string) (*gorm.DB, error) {
db, err = gorm.Open(postgres.Open(dataSourceName), &gorm.Config{})
} else if driverName == "mysql" {
db, err = gorm.Open(mysql.Open(dataSourceName), &gorm.Config{})
//} else if driverName == "sqlite3" {
// db, err = gorm.Open(sqlite.Open(dataSourceName), &gorm.Config{})
//} else if driverName == "sqlite3" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it.

Copy link
Contributor Author

@miaolz123 miaolz123 Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change of these lines is just for code format.

// Example: gormadapter.NewAdapterByDBUseTableName(&db, "cms", "casbin") Automatically generate table name like this "cms_casbin"
func NewAdapterByDBUseTableName(db *gorm.DB, prefix string,tablename string) (*Adapter, error) {
func NewAdapterByDBUseTableName(db *gorm.DB, prefix string, tablename string) (*Adapter, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to NewAdapterByDBWithTableName(), arg to tableName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the change of this line is just for code format and I have no plans to unify code-style at this PR.

@@ -148,14 +151,19 @@ func NewAdapter(driverName string, dataSourceName string,params ...interface{})
return a, nil
}

// NewAdapterByDB obtained through an existing Gorm instance get a adapter, specify the table prefix and the table name
// NewAdapterByDBUseTableName obtained through an existing Gorm instance get a adapter, specify the table prefix and the table name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obtained through an existing Gorm instance get a adapter

This sentense doesn't make sense. Change it to smooth English.

@@ -164,17 +172,9 @@ func NewAdapterByDBUseTableName(db *gorm.DB, prefix string,tablename string) (*A
return a, nil
}

// NewAdapterByDB obtained through an existing Gorm instance get a adapter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obtained through an existing Gorm instance get a adapter

This sentense doesn't make sense. Change it to smooth English.

@hsluoyz
Copy link
Member

hsluoyz commented Sep 19, 2020

@miaolz123 reviewed.

@miaolz123
Copy link
Contributor Author

To be honest, I submitted this PR only to fix default table name bug which make the access-control of my project doesn't work right.

Due to the limited free time, I have no plans to unify code-style and commet-spell at this PR.

please close this PR if you think my modified code is unacceptable. I can accept it totally.

@hsluoyz
Copy link
Member

hsluoyz commented Sep 21, 2020

This PR is acceptable. I just found some other places that can be improved. I will find others to finish what I proposed. Thanks.

@hsluoyz hsluoyz merged commit ff42705 into casbin:master Sep 21, 2020
@hsluoyz
Copy link
Member

hsluoyz commented Sep 21, 2020

@00LT00 please send a new PR to fix what I have commented in this PR.

@00LT00
Copy link
Member

00LT00 commented Sep 21, 2020

ok

@hsluoyz
Copy link
Member

hsluoyz commented Sep 21, 2020

@00LT00 you can first create an issue to track this.

@00LT00 00LT00 mentioned this pull request Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants