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

Override table name when executing SQL #154

Open
bitxel opened this issue Jun 9, 2018 · 2 comments · May be fixed by #167
Open

Override table name when executing SQL #154

bitxel opened this issue Jun 9, 2018 · 2 comments · May be fixed by #167

Comments

@bitxel
Copy link

bitxel commented Jun 9, 2018

Dear developers,

Thanks for your hard work, this library help me a lot, and I have a question about the table name:
As state in the ReadMe doc, the following struct will map to person table,

//reform:people
type Person struct {
	ID        int32      `reform:"id,pk"`
	Name      string     `reform:"name"`
	Email     *string    `reform:"email"`
	CreatedAt time.Time  `reform:"created_at"`
	UpdatedAt *time.Time `reform:"updated_at"`
}

After diving into code, I didn't find any way to reuse this Person struct to other table with the same structure, please advice if I miss any parts:)

So I'd like to propose a set of new Functions like SaveOnTable(record, table_name), UpdateOnTable(record, table_name) etc, which will execute SQL on the appointed table and make it possible to reuse this struct on many tables or sharding tables, like:

person_00
person_01
... 
person_99

Please help review this feature request.

@AlekSi
Copy link
Member

AlekSi commented Jun 9, 2018

Hi. Thank you for using reform and helping make it better!

#62 describes a similar, but not identical issue.

I think something like this could work:

// WithTag returns a copy of Querier with set view name. Returned Querier is tied to the same DB or TX.
func (q *Querier) WithView(viewName) *Querier {
  // …
}

// …

DB.WithView("person_42").Save(record)

I would be happy to accept a PR for that issue!

@AlekSi AlekSi added this to the v1.4.0 milestone Jun 9, 2018
@bitxel
Copy link
Author

bitxel commented Jun 11, 2018

Yeah, this way sounds better, I'll work on it.

@AlekSi AlekSi linked a pull request Jul 31, 2018 that will close this issue
2 tasks
@AlekSi AlekSi modified the milestones: v1.4.0, v1.5.0 Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants