Improve schema generation
I believe a good ORM should abstract the user from writing any kind of SQL, at least for normal operation. Having this into account, kallax' schema generation feature needs some improvements.
In the near future, what I think it would be useful is:
Schema generation
- [ ] Add support for indices via struct tags
- [ ] Simple indices, with sorting option
- [ ] Compound indices
Migrations
- [ ] When manual migration is required, hint the user which sql they should run with a comment in the migration script
This is an open discussion. Feel free to suggest another features regarding this functionality.
Hi! I would love to help on adding simple indices, would you mind if I give it a go? 😄
@Maaarcocr Of course! But please take into account that PR require minimal documentation (both on README and as godoc comments) and test cases covering basic usage to be merged.
Great suggestion! you expected like this?
// model struct definition
// users table has (org_id, user_id) unique index foo
type User struct {
OrgId int `index:"foo"`
UserId int `index:"foo"`
}
// generated UserQuery can query by foo index
userQuery.FindByFooIndex(orgId, userId)
I don't think the FindByFooIndex is neccesary. Postgres should automatically use index if the conditions specified in the WHERE clause allow it.
Regarding the struct tag, I think it should be something along the lines of:
type User struct {
Email string `index:""`
Age int `index:"asc"`
}
This is, specifying the name of the index seems unnecessary to me (it should be a unique name, autogenerated by kallax), and allowing to specify the index default sorting option may have some value. This sorting option thing is not prioritary tho.