pilagod / gorm-cursor-paginator

A paginator doing cursor-based pagination based on GORM
https://github.com/pilagod/gorm-cursor-paginator
MIT License
192 stars 44 forks source link

use schema DBName to parse SQLKey #49

Closed goxiaoy closed 1 year ago

goxiaoy commented 1 year ago

SQLKey is hard coded as snake case, but GORM has configuration NamingStrategy This pr use schema.LookUpField(key).DBName to get database name of key field

see https://gorm.io/docs/gorm_config.html#NamingStrategy

goxiaoy commented 1 year ago

One thing I'm not sure to note here is that, from my understanding gorm.Statement.Parse would only run in local cache, and won't talk to DB, right?

That's true.

But if it is not true, we might need to consider parsing schema at somewhere only once, and maybe caching it on paginator instance.

This is implemented by gorm internally by DB.cacheStore, see https://github.com/go-gorm/gorm/blob/c3d7d08b9a9f861e53e8b194fcc6b7cedc4191e1/schema/schema.go#L304-L309

pilagod commented 1 year ago

Nice, learn a lot from this PR. 🙌 All looks good to me. I will prepare a new version after merging.

pilagod commented 1 year ago

@goxiaoy I just released v2.4.0 to include your changes. Thanks again for the contribution, it helps a lot 🙌

And sorry about that I didn't aware debug mode generating too many messages that interferes development and testing, so I disable it by default. You can enable it for local debug at will, but just skip committing it to the repo 😃