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

Connect to specific table #3

Closed
julisch94 opened this issue Aug 10, 2017 · 5 comments
Closed

Connect to specific table #3

julisch94 opened this issue Aug 10, 2017 · 5 comments
Assignees

Comments

@julisch94
Copy link

How do I connect to a specific table inside an sqlite database?
adapter := xormadapter.NewAdapter("sqlite3", "./database.db", true) connects successfully with my sqlite database, but creates a default table casbin_rules.

adapter := xormadapter.NewAdapter("sqlite3", "./database.db/mytable", true) unfortunately interprets database.db as directory.

@hsluoyz
Copy link
Member

hsluoyz commented Aug 10, 2017

Currently Xorm will automatically name the table after the struct being stored. based on Xorm docs. The struct is:

type CasbinRule struct {
	PType string `xorm:"varchar(100)"`
	V0    string `xorm:"varchar(100)"`
	V1    string `xorm:"varchar(100)"`
	V2    string `xorm:"varchar(100)"`
	V3    string `xorm:"varchar(100)"`
	V4    string `xorm:"varchar(100)"`
	V5    string `xorm:"varchar(100)"`
}

So the default table name would be casbin_rule. And the table would be just as the struct definition. So basically you can't reuse an existing table that has other structures. Would you tell me why you want to rename the table name?

@hsluoyz hsluoyz self-assigned this Aug 10, 2017
@julisch94
Copy link
Author

julisch94 commented Aug 10, 2017

I was wondering if there's a way to reconfigure the names of the tables and its columns. I saw the struct you've posted already in the code but found no way to change it.

So I can't change the used database name. That's alright for me.
Does that mean that I can't change the column names in casbin_rule (p_type, v1, etc.) either?

@hsluoyz
Copy link
Member

hsluoyz commented Aug 10, 2017

I can't change the used database name.

I don't understand. The DB for SQLite is the .db file, which is controlled by you.

Does that mean that I can't change the column names in casbin_rule (p_type, v1, etc.) either?

I think the simplest and most direct way to do it is renaming the struct CasbinRule and its members. Then the table and column names will change at the same time. You can do this job within a IDE, so all references will change too.

@julisch94
Copy link
Author

Thank you very much. I will try that.

@julisch94
Copy link
Author

By the way, it worked. Renaming the struct CasbinRule and its members makes the created table and its columns be named accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants