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 to modify tablename with plugin and callback? #7326

Open
so2bin opened this issue Dec 23, 2024 · 0 comments
Open

How to modify tablename with plugin and callback? #7326

so2bin opened this issue Dec 23, 2024 · 0 comments
Assignees
Labels
type:question general questions

Comments

@so2bin
Copy link

so2bin commented Dec 23, 2024

Your Question

What I Want

  • Now I am using the TiDB sqlparser github.com/pingcap/tidb/pkg/parser to modify the SQL, for example:
type MirrorTableModifier struct {
	tblNameMap map[string]string
}

func (m *MirrorTableModifier) Enter(in ast.Node) (ast.Node, bool) {
	switch node := in.(type) {
	case *ast.TableName:
		if modifyName, ok := m.tblNameMap[node.Name.String()]; ok {
			node.Name = model.NewCIStr(modifyName)  // modify table name here
		}
	}
	return in, false
}

func (m *MirrorTableModifier) Leave(in ast.Node) (ast.Node, bool) {
	return in, true
}
  • So how can I use this sqlparser together with gorm callback?
@so2bin so2bin added the type:question general questions label Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

2 participants