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

How can I set a table prefix from config??? #49

Open
maximniko opened this issue Sep 26, 2017 · 3 comments
Open

How can I set a table prefix from config??? #49

maximniko opened this issue Sep 26, 2017 · 3 comments

Comments

@maximniko
Copy link

maximniko commented Sep 26, 2017

I use github.com/qiangxue/golang-restful-starter-kit bun can`t find, how can I set table_prefix from config

server.go > buildRouter () {
...
artistDAO := daos.NewArtistDAO()
apis.ServeArtistResource(rg, services.NewArtistService(artistDAO))
}

Error:
level=error msg="Error 1146: Table 'db.table' doesn't exist"

I need set table-prefix from config by this query "SELECT * FROM db.prefixTable ..."

@kPshi
Copy link

kPshi commented Oct 13, 2017

You can set the whole table name by implementing the TableModel interface:

type TableModel interface {
    TableName() string
}

E.g. like

func (ArtistDAO) TableName() string {
    return "myprefix_artists";
}

or

    // snip
    return myDynamicPrefix()+"artists"

but I do agree with you that a prefix would be very helpful. Currently having the same prob here. Maybe one should implement it and make a pull request.

@kPshi
Copy link

kPshi commented Jul 23, 2018

About to implement that. One topic I'd like to discuss:
struct.go defines

251:  func GetTableName(a interface{}) string {
...:      // snip
268: }

as a static function. Is there a reason to implement it statically instead of an instance method of *DB for example? The latter would allow to configure it in a clean way and also allow to use ozzo-dbx multiple times in a single process, possibly connecting to the same database instance only using different table prefixes.
I'd personally prefer that latter implementation and would (if not suggested differently here) leave the old static method in for now so that software already using ozzo does not have to be changed.

Comments?

@qiangxue : maybe that topic could benefit by your opinion on that.

@kPshi
Copy link

kPshi commented Aug 9, 2018

Implemented with pull request #69

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

No branches or pull requests

2 participants