/
githubmirror
/
GoFrame
Обзор
Документация
Войти
/
githubmirror
/
GoFrame
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
database/gdb/gdb_model_transaction.go
28 строк
904 B
John Guo
feature/v2.3.0 (#2296)
09 янв 2023, 09:43
Не верифицирован
09 янв 2023, 09:43
5e72b03
Код
Авторство
О чём код?
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. // // This Source Code Form is subject to the terms of the MIT License. // If a copy of the MIT was not distributed with this file, // You can obtain one at https://github.com/gogf/gf. package gdb import ( "context" ) // Transaction wraps the transaction logic using function `f`. // It rollbacks the transaction and returns the error from function `f` if // it returns non-nil error. It commits the transaction and returns nil if // function `f` returns nil. // // Note that, you should not Commit or Rollback the transaction in function `f` // as it is automatically handled by this function. func (m *Model) Transaction(ctx context.Context, f func(ctx context.Context, tx TX) error) (err error) { if ctx == nil { ctx = m.GetCtx() } if m.tx != nil { return m.tx.Transaction(ctx, f) } return m.db.Transaction(ctx, f) }