Begin starts a new transaction. Multiple read-only transactions can be used concurrently but only one write transaction can be used at a time. Starting multiple write transactions will cause the calls to block and be serialized until the current write transaction finishes. Transactions should not b
(writable bool)
| 765 | // IMPORTANT: You must close read-only transactions after you are finished or |
| 766 | // else the database will not reclaim old pages. |
| 767 | func (db *DB) Begin(writable bool) (t *Tx, err error) { |
| 768 | if lg := db.Logger(); lg != discardLogger { |
| 769 | lg.Debugf("Starting a new transaction [writable: %t]", writable) |
| 770 | defer func() { |
| 771 | if err != nil { |
| 772 | lg.Errorf("Starting a new transaction [writable: %t] failed: %v", writable, err) |
| 773 | } else { |
| 774 | lg.Debugf("Starting a new transaction [writable: %t] successfully", writable) |
| 775 | } |
| 776 | }() |
| 777 | } |
| 778 | |
| 779 | if writable { |
| 780 | return db.beginRWTx() |
| 781 | } |
| 782 | return db.beginTx() |
| 783 | } |
| 784 | |
| 785 | func (db *DB) Logger() Logger { |
| 786 | if db == nil || db.logger == nil { |