Commit Graph

120 Commits

Author SHA1 Message Date
Charles Strahan b543a11ca0 transaction blocks: don't swallow panics (#2774)
This improves upon #2767.

Previously, the code would swallow any panics, which isn't ideal;
panic is intended to be used when a critical error arises,
where the process should fail fast instead of trying to limp along.

This now defers the any recovery (if desired) to the client code.
2019-12-05 17:54:32 +08:00
Jason Lee 59408390c2 Add `db.Transaction` method for create Transaction block. (#2767)
* Add `db.Transaction` method for create Transaction block.

example:

```go
func CreateAnimals(db *gorm.DB) error {
  db.Transaction(func(tx *gorm.DB) error {
    if err := tx.Create(&Animal{Name: "Giraffe"}).Error; err != nil {
      // return any error will rollback
      return err
    }

    if err := tx.Create(&Animal{Name: "Lion"}).Error; err != nil {
      return err
    }

    // return nil will commit
    return nil
  })
}
```

* Ensure rollback when commit has error.
2019-11-19 16:08:00 +08:00
Jinzhu 5acd5e20e6 Remove Debug mode from test code 2019-06-13 12:20:11 +08:00
Jinzhu ff430cad49 Update tests 2019-06-13 11:21:13 +08:00
Jinzhu 153ce22c99 Test Save with specfied table name 2019-06-11 17:30:14 +08:00
Tyler Stillwater fec06da6a3 Add BeginTx for parity with sql.DB.BeginTx (#2227) 2019-06-11 12:22:21 +08:00
Adam S Levy f301f86e29 Add RollbackUnlessCommitted() (#2126) 2019-06-11 12:22:21 +08:00
John Barker 280dd011a1 Don't AddError for Rollback on ErrTxDone (#2434) 2019-06-11 12:22:20 +08:00
Emir Beganovic 394b3a1818 Fixed nil error when first updates with struct 2019-05-05 13:12:03 +04:00
Emir Beganovic abe3fa8631 Run only on MySQL and sqlite 2019-05-05 11:51:05 +04:00
Emir Beganovic 741cd60b1b Add test for keeping float precision 2019-05-05 11:24:26 +04:00
Dmitry Zenovich 483c2ef521 Merge branch 'master' into pluck 2019-04-30 17:28:56 +03:00
Dmitry Zenovich adc8e9b706 apply gorm:query_option in Count() 2019-04-19 14:48:52 +03:00
Dmitry Zenovich 8d1e6bc0f8 remove old elements from the output parameter of Pluck() 2019-04-19 14:41:30 +03:00
Emir Beganovic 59594877da Fix unsafe concurrent SingularTable method call 2019-04-14 12:30:11 +04:00
Wendell Sun 26e8799a19 fix the case that using Having on Count 2019-03-11 21:16:50 +08:00
Ikhtiyor d3e666a1e0 save_associations:true should store related item (#2067)
* save_associations:true should store related item, save_associations priority on related objects

* code quality
2018-09-10 06:25:26 +08:00
Xy Ziemba 71b7f19aad Fix scanning identical column names occurring >2 times (#2080)
Fix the indexing logic used in selectedColumnsMap to skip fields
that have already been seen. The values of selectedColumns map
must be indexed relative to fields, not relative to selectFields.
2018-09-10 06:12:58 +08:00
Daniel McDonald 35efe68ba7 add simple input validation on gorm.Open function (#1855)
Simply check if the passed-in database source meets the expected types
and, if not, early return with error.
2018-05-02 09:37:51 -05:00
Jinzhu 86c04795b7 Port PR #1655 to Not query builder 2018-02-11 15:52:52 +08:00
andrew 8d66eb4926 fixed wrong param substitution order 2018-02-11 14:58:22 +08:00
Jinzhu e0f9087c8d Setup test env 2018-02-10 11:07:07 +08:00
Jinzhu 2c68f695c3 Set AutoIncrement to false with tag 2018-02-10 08:24:39 +08:00
Jinzhu c3bb6aaa82 Fix QueryExpr tests 2017-08-11 23:24:00 +08:00
Jinzhu e5432b14d2 Add QueryExpr, thanks @ManReinsp for PR #1548 2017-08-11 18:41:04 +08:00
Jinzhu 5730b92954 Fix tests with mssql 2017-03-22 23:50:42 +08:00
Jinzhu 403487d5dd Setup mssql test env 2017-03-22 23:50:42 +08:00
Jinzhu c730b30a78 Fix "Unsupported destination" error when value is pointer of pointer 2017-02-07 08:32:18 +08:00
slockij e26cb8dbc4 In some cases (Error not checked, missed data) one can perform very harmful operation - global update or delete (all records)
This is to prevent it.
2016-11-04 17:54:43 +01:00
Jinzhu c1b9cf186e Merge pull request #1210 from baijum/error-zero-args
If no arguments, return error at once
2016-10-23 22:58:23 +08:00
Jinzhu 89b7cbe89c Fix RowsAffected not returned for FirstOrCreate 2016-10-21 11:30:17 +08:00
Jinzhu 5d853fc53c Fix null time not allowed in mysql5.7 test error 2016-10-19 12:20:45 +08:00
Baiju Muthukadan bd513dd580 test case for single parameter for Open 2016-10-08 21:52:15 +05:30
Jinzhu 02f6ae3c4e If failed to update current record with Save, try to create a new one 2016-09-07 21:54:19 +08:00
zardak ccb35db934 Fix failing sqlite3 tests due to db connection not being closed 2016-08-13 21:05:24 +08:00
Vladislav Fursov e8c14bd1b3 Fixed a bug when joining multiple tables with the same fields and where on the same field. 2016-08-09 14:28:43 +09:00
Jinzhu 18917d1f3e Merge pull request #1028 from nkovacs/wercker
Wercker postgres and mysql
2016-06-16 18:29:11 +08:00
Andrey Nering 7248671c9a Allow run tests for SQLite on Windows 2016-05-28 13:49:32 -03:00
Nikola Kovacs 6fca4ec9fe Add wercker.yml with postgres and mysql tests 2016-05-22 01:59:25 +02:00
Jinzhu 7c43d9fc36 Fix scan columns with same name 2016-03-10 17:35:19 +08:00
Jinzhu d08894cd69 Rename test files 2016-03-08 22:00:15 +08:00
Jinzhu ec110657da Refactor based on golint 2016-03-07 17:49:55 +08:00
Jinzhu c811590d4e Add dialects for supported databases for easier to use 2016-03-05 18:54:59 +08:00
Jinzhu f57198fe97 Test multiple Joins 2016-02-21 10:55:36 +08:00
Jinzhu 115789960a Joins support parameters, close #673 2016-02-16 22:48:26 +08:00
Jinzhu 6546ec3b5e Scan Rows into struct, fix #59 2016-02-14 23:29:06 +08:00
Jinzhu 86b4b20278 Merge branch 'master' into v1.0_dev 2016-02-14 14:18:35 +08:00
Richard Knop f73f7b251f HasTable now works with table name passed as a string.
Before, only HasTable(&Foo) would work but HasTable("foos") would always
return false. This PR fixes that.
2016-02-13 20:28:42 +08:00
Jinzhu 8d716be896 Fix some go vet/lint reports 2016-01-15 21:16:48 +08:00
Jinzhu f0364a0fb5 Merge branch 'master' into v1.0_dev 2016-01-12 15:47:50 +08:00