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

Columns should have type safety #5

Open
rdelossantos opened this issue Jan 21, 2015 · 4 comments
Open

Columns should have type safety #5

rdelossantos opened this issue Jan 21, 2015 · 4 comments
Assignees

Comments

@rdelossantos
Copy link

I believe it should be a great feature if we can have struct tags generated for sql column names. Ex:

objs.Select("Id", "Age").Where(objs.FilterAge(">=", 10)).
OrderBy("Age", "+Id").Page(9, 5)

Should be:

objs.Select(User.Id, User.Age).Where(objs.FilterAge(">=", 10)).
OrderBy(User.Age, User.Id).Page(9, 5)

Or

objs.Select( _.Id, _.Age).Where(objs.FilterAge(">=", 10)).
OrderBy( _.Age, _.Id).Page(9, 5)**

This is very important when you're designing big projects and you're refactoring the database models. The compiler we'll help to identify the errors after code generation from the refactored database.

@mijia
Copy link
Owner

mijia commented Jan 21, 2015

@rdelossantos Yes, that will make sense. We should have a unique Column interface for this, I have generated the code for this, but want to wait until I figured out how to do the count(*), sum(age) and etc stuff.

Any suggestions, :)

@mijia mijia self-assigned this Jan 21, 2015
@rdelossantos
Copy link
Author

For aggregate functions i believe it should be a simple string decorator:

Sum(field_var) => "sum(field_var)"

Ex:

objs.Select(User.Age, Max(User.Id)).Where(objs.FilterAge(">=", 10)).
GroupBy(User.Age)

Sum, Max, Min, etc. should concatenate the original field name and add the corresponding prefix and suffix for the sql aggregate function.

On execution it we'll return an error if a column is not grouped by and without aggregate function. Maybe in a later version it could be a more advanced feature with type safety.

From my point of view the library should be experimental before 1.0 release but should handle the 90% of tedious tasks like joins and aggregate functions.

@mijia
Copy link
Owner

mijia commented Jan 21, 2015

From my point of view the library should be experimental before 1.0 release but should handle the 90% of tedious tasks like joins and aggregate functions.

Yes, definitely.
The SQL generating part is easy one, but in Select query, ModelQ will return a model struct which has all the typed data in it. But the count(x) or sum(x) is not part of the model struct which I think will need the join to figured out first, :)

@rdelossantos
Copy link
Author

I'm too new to the Go Type system and i can't help for now, On next week i'll try to understand all the internals of the package, Thanks for your great work :).

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

2 participants