mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
dialect/sqlscan: add ScanInt64 to be used by sqlgraph
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/213 Reviewed By: alexsn Differential Revision: D18763694 fbshipit-source-id: 890b35fcc2a28914b276ce65477788b4ddaeebf9
This commit is contained in:
committed by
Facebook Github Bot
parent
a4fac2db3b
commit
a5e4a9cf54
@@ -351,25 +351,14 @@ func insertLastID(ctx context.Context, tx dialect.ExecQuerier, insert *InsertBui
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
if !rows.Next() {
|
||||
return 0, fmt.Errorf("no rows found for query: %v", query)
|
||||
}
|
||||
var id int64
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return id, nil
|
||||
return ScanInt64(rows)
|
||||
}
|
||||
// MySQL, SQLite, etc.
|
||||
var res sql.Result
|
||||
if err := tx.Exec(ctx, query, args, &res); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return id, nil
|
||||
return res.LastInsertId()
|
||||
}
|
||||
|
||||
// rollback calls to tx.Rollback and wraps the given error with the rollback error if occurred.
|
||||
|
||||
Reference in New Issue
Block a user