-
Notifications
You must be signed in to change notification settings - Fork 213
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
SetError #150
Comments
Not currently but I can see how it would be useful. I think we should add it to all the dataset types to keep consistency. |
@doug-martin I'd like to try to get this working in a PR. I started what I thought would be pretty straightforward by doing this:
For all the dataset types. The
So I tried a type-assertion:
Which causes more type problems:
I'm clearly doing this wrong. Do you see a better way to implement |
I almost think that |
I think a solution that may work, to keep changes to a minimum, could be to add a SetError method to each Dataset, and in the sqlBuilder method set the error if it exists on the dataset. So for DeleteDataset the changes could be. type DeleteDataset struct {
dialect SQLDialect
clauses exp.DeleteClauses
isPrepared bool
queryFactory exec.QueryFactory
err error
} // used interally to copy the dataset
func (dd *DeleteDataset) copy(clauses exp.DeleteClauses) *DeleteDataset {
return &DeleteDataset{
dialect: dd.dialect,
clauses: clauses,
isPrepared: dd.isPrepared,
queryFactory: dd.queryFactory,
err: dd.err,
}
} func (dd *DeleteDataset) deleteSQLBuilder() sb.SQLBuilder {
buf := sb.NewSQLBuilder(dd.isPrepared)
if dd.err != nil {
return buf.SetError(dd.err)
}
dd.dialect.ToDeleteSQL(buf, dd.clauses)
return buf
} The same pattern would be followed for the other datasets. If you can think of a way to abstract that logic out go for it. Hope this helps. |
If you are going to work this I'd like to get it in before merging #151, since it could be part v8. Let me know your thoughts. |
I agree. I think the suggestion you have will work great. I think I can have something ready tomorrow. Then we can work on getting in #151 afterwards. Thanks so much for your help, it's been very appreciated! |
@doug-martin I've gone with the suggestion you gave me and created a PR: #152 There's a fair bit of code duplication but without some major refactoring I didn't see a simple way around that. And I wanted to keep this change simple. I did add some tests around the new behavior as well. Please let me know what you think. |
@marshallmcmullen just released this, Great job! |
Woohoo! Great news. Thanks for helping me through my first goqu PR @doug-martin ! |
Is there a way to set an error on a
SelectDataset
(or any other dataset for that matter) ? It would be super convenient if my code which is building up a query using goqu could leverage its internal error tracking so a subsequentToSQL
would give me back the error I set (or any other internal goqu error) instead of me having to add another layer on top of goqu to track this.Here's some pseudocode example of what I'd like to be able to do:
Then, later on when I go to execute the resulting SQL, this would provide a really nice idiomatic way to detect and propagate the error:
Thoughts? Better ideas on how to handle this ?
Thanks!!
The text was updated successfully, but these errors were encountered: