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

Improve schema generation #243

Open
4 tasks
roobre opened this issue Nov 23, 2017 · 4 comments
Open
4 tasks

Improve schema generation #243

roobre opened this issue Nov 23, 2017 · 4 comments

Comments

@roobre
Copy link
Contributor

roobre commented Nov 23, 2017

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.

@Maaarcocr
Copy link

Hi! I would love to help on adding simple indices, would you mind if I give it a go? 😄

@roobre
Copy link
Contributor Author

roobre commented Dec 3, 2017

@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.

@kamichidu
Copy link
Contributor

kamichidu commented Dec 11, 2017

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)

@roobre
Copy link
Contributor Author

roobre commented Dec 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants