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 do I get the pluralized name of a table the same way bun would? #885

Open
codeliger opened this issue Aug 20, 2023 · 0 comments
Open

Comments

@codeliger
Copy link
Contributor

Is there a way to get companies or users or hypothetically users_orders from a bun model for this use case?

I need to update the sequence of a lot of tables because inserting fixtures with static ids doesn't update the sequences in postges

var Models []interface{} = []interface{}{
	(*Company)(nil),
	(*User)(nil),
	(*Order)(nil),
}
	
	
for _, model := range models.Models {
	// get name of struct using reflect / inflection packages?

	_, err = db.NewRaw("SELECT setval(pg_get_serial_sequence('?', 'id'), (SELECT MAX(id) FROM ?));").Exec(context.Background())
	if err != nil {
		panic(err)
	}
}
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

1 participant