-
-
Notifications
You must be signed in to change notification settings - Fork 230
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
feat: added raw query calls #596
Conversation
Hey, The suggested API looks like this: err := db.Raw(query, args...).Scan(ctx, &strct)
err := db.Raw(query, args...).Scan(ctx, &slice)
err := db.Raw(query, args...).Scan(ctx, &var1, &var2) The implementation should look like this: func (db *DB) Raw(query string, args ...interface{}) *RawQuery {
return &RawQuery{
db: db,
query: query,
args: args,
}
}
type RawQuery struct {
db *DB
query string
args ...interface{}
}
func (q *RawQuery) Scan(ctx context.Context, dest ...interface{}) error {
// extract and reuse Scan implementation from SelectQuery.Scan
// to format the query, use query := db.format(q.query, q.args)
return scanModel(...)
} Does that make sense? |
Did you mean something like that? |
Yes, exactly 👍 Could you add a simple test like |
query_raw.go
Outdated
query := []byte(fmter.FormatQuery(q.query, q.args)) | ||
b = append(b, query...) | ||
|
||
return b, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be return fmter.AppendQuery(b, q.query, q.args), nil
Let me know if you see the need to change something else |
Very good - thanks 👍 |
Added raw query support: #593