a41f938cec
As we have seen, dependencies version can prevent the build. We should user lock versions on dependencies that we know work: * Packages are vendored * Add Godep support * Added addtional install step in readme * Fix travis build error
30 lignes
730 o
Go
30 lignes
730 o
Go
package gorm
|
|
|
|
import "database/sql"
|
|
|
|
// Define callbacks for row query
|
|
func init() {
|
|
DefaultCallback.RowQuery().Register("gorm:row_query", rowQueryCallback)
|
|
}
|
|
|
|
type RowQueryResult struct {
|
|
Row *sql.Row
|
|
}
|
|
|
|
type RowsQueryResult struct {
|
|
Rows *sql.Rows
|
|
Error error
|
|
}
|
|
|
|
// queryCallback used to query data from database
|
|
func rowQueryCallback(scope *Scope) {
|
|
if result, ok := scope.InstanceGet("row_query_result"); ok {
|
|
scope.prepareQuerySQL()
|
|
|
|
if rowResult, ok := result.(*RowQueryResult); ok {
|
|
rowResult.Row = scope.SQLDB().QueryRow(scope.SQL, scope.SQLVars...)
|
|
} else if rowsResult, ok := result.(*RowsQueryResult); ok {
|
|
rowsResult.Rows, rowsResult.Error = scope.SQLDB().Query(scope.SQL, scope.SQLVars...)
|
|
}
|
|
}
|
|
}
|