Refactor callbck_create
This commit is contained in:
parent
e30cf3bbd1
commit
5823670269
@ -60,21 +60,13 @@ func Create(scope *Scope) {
|
|||||||
if result, err := scope.DB().Exec(scope.Sql, scope.SqlVars...); scope.Err(err) == nil {
|
if result, err := scope.DB().Exec(scope.Sql, scope.SqlVars...); scope.Err(err) == nil {
|
||||||
id, err = result.LastInsertId()
|
id, err = result.LastInsertId()
|
||||||
if scope.Err(err) == nil {
|
if scope.Err(err) == nil {
|
||||||
if count, err := result.RowsAffected(); err == nil {
|
scope.db.RowsAffected, _ = result.RowsAffected()
|
||||||
scope.db.RowsAffected = count
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if scope.PrimaryKey() == "" {
|
if scope.PrimaryKey() == "" {
|
||||||
if rows, err := scope.DB().Query(scope.Sql, scope.SqlVars...); err != nil {
|
if results, err := scope.DB().Exec(scope.Sql, scope.SqlVars...); err != nil {
|
||||||
//extract column name to get fields lenght
|
scope.db.RowsAffected, _ = results.RowsAffected()
|
||||||
if names, columnsErr := rows.Columns(); columnsErr != nil {
|
|
||||||
ids := make([]interface{}, len(names))
|
|
||||||
if scope.Err(rows.Scan(ids...)) == nil {
|
|
||||||
scope.db.RowsAffected = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if scope.Err(scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&id)) == nil {
|
if scope.Err(scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&id)) == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user