Commit Graph

1757 Commits

Author SHA1 Message Date
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
Emir Beganović 179760d834
Merge pull request #2722 from kohago/master
Add warning comment
2019-10-28 12:18:11 +04:00
Emir Beganović e359feee63
Merge branch 'master' into master 2019-10-28 12:09:43 +04:00
Emir Beganović 2586a05016
Merge pull request #2721 from rubensayshi/isforeignkeyrace
fix a race condition on IsForeignKey that is being detected by -race
2019-10-28 12:09:32 +04:00
Emir Beganović 8420e321b0
Merge branch 'master' into isforeignkeyrace 2019-10-28 12:02:16 +04:00
Emir Beganović 4bd563826b
Merge pull request #2728 from dnathe4th/dn-log-register
Log callback registration if logger exists for consistency
2019-10-28 11:12:32 +04:00
Dom Narducci c46c01c116 Log callback registration if logger exists for consistency 2019-10-25 13:51:29 -07:00
kouha.shu 2ee239a4c0 Update main.go 2019-10-23 10:40:34 +09:00
kouha.shu d926a05bec add warning comment 2019-10-23 10:38:05 +09:00
Ruben de Vries 530711e724
fix a race condition on IsForeignKey that is being detected by -race sometimes. 2019-10-22 11:35:11 +02:00
FWangZil 795328fedc fix(HasTable): database name (#2717)
* fix(HasTable): database name
allow mysql database name with '-' character

* docs: add comment
2019-10-21 20:45:38 +08:00
Jinzhu 5fe32d593f Escape table name for mysql HasTable 2019-10-21 20:20:38 +08:00
macklin-10x 5b3e40ac12 Rename expr type to make it public. (#2604) 2019-10-17 23:44:34 +08:00
aimuz a8a530db5a SetColumn No fields ignored were processed (#2579) 2019-10-17 23:38:37 +08:00
lotus.wu b99f2d8270 1. suport date time '2070-03-30 00:00:00',timestamp can't support large date time. (#1823) 2019-10-17 23:36:06 +08:00
okhowang 120d39b4d6 use show statement in mysql dialect for compatibility for tencent tdsql (#2643) 2019-10-17 23:22:13 +08:00
Lilit 7729627ff6 Fix logging callbacks (#2652) 2019-10-17 23:12:01 +08:00
Devin Samarin d2007b3c82 Describe name of field for invalid SQL datatypes (#2689) 2019-10-17 22:56:19 +08:00
Alex Stockwell 820b5f244a MSSQL Create() fix: Add LastInsertIDReturningSuffix to dialect (#2690)
* MSSQL Create() fix: Add LastInsertIDReturningSuffix to dialect

Per https://github.com/denisenkom/go-mssqldb/issues/355

* MSSQL Create() fix: Added OUTPUT query to Create() builder
2019-10-17 22:54:11 +08:00
Emir Beganović 1bca5dbdd9
Merge pull request #2691 from ken8203/bugfix/fix-typo-of-example-code
Fix typo of example code
2019-10-08 12:04:52 +02:00
Jay Chung e5d0267c0b Fix typo of example code 2019-10-05 12:12:47 +08:00
Emir Beganović 81c17a7e25 Revert "Fix #2517 : Check for incomplete parentheses to prevent SQL injection." (#2674)
This reverts commit e3cc5ea4d4.
2019-09-25 19:22:43 +08:00
Christian Muehlhaeuser 0c98e7d712 Fixed import formatting to match goimports (#2568) 2019-09-12 22:17:31 +08:00
Shunsuke Otani 13f19a5036 Uncapitalize error strings (#2533) 2019-09-12 22:16:52 +08:00
Shunsuke Otani d5cafb5db1 Fix CallbackProcessor.Get() for removed or replaced same name callback (#2548) 2019-09-12 22:16:05 +08:00
Steve Ellis b954854116 bump mattn/go-sqlite3 to v1.11.0 (#2565) 2019-09-12 22:13:59 +08:00
haoc7 2a3ab99a08 fix insert timezero 0001-01-01 (#2635) 2019-09-02 09:44:50 +08:00
Emir Beganović 836fb2c19d
Fix #2517 : Check for incomplete parentheses to prevent SQL inj… (#2519)
Fix #2517 : Check for incomplete parentheses to prevent SQL injection.
2019-06-30 11:50:19 +04:00
Herpiko Dwi Aguno 8215224f7b
Merge branch 'master' into 2517 2019-06-25 16:24:36 +07:00
Herpiko Dwi Aguno e3cc5ea4d4 Fix #2517 : Check for incomplete parentheses to prevent SQL injection. 2019-06-25 16:21:45 +07:00
Emir Beganović a6b790ffd0
Fix function name of comment (#2522)
Fix function name of comment
2019-06-25 10:50:53 +02:00
zaneli beb591e642 Fix function name of comment 2019-06-24 20:38:13 +09:00
Jinzhu 01b6601142 Update go.mod 2019-06-13 14:42:55 +08:00
Jinzhu 5acd5e20e6 Remove Debug mode from test code 2019-06-13 12:20:11 +08:00
Jinzhu 835ca6ca93 Update wercker.yml to include mysql 8 2019-06-13 11:48:31 +08:00
Jinzhu ff430cad49 Update tests 2019-06-13 11:21:13 +08:00
Jinzhu 321c636b9d Merge branch 'Momo733-master' 2019-06-11 17:32:55 +08:00
Momo733 781a818390 fix save err when specify a table name
s.New() will clear all search conditions and search value,when I use Table() to set a table name. Then FirstOrCreate() will use struct name as my database table name,so It doesn't work.
2019-06-11 17:30:29 +08:00
Jinzhu 153ce22c99 Test Save with specfied table name 2019-06-11 17:30:14 +08:00
Ruben de Vries c44c6027fb add an override on the DB instance instead of using the global NowFunc. (#2142) 2019-06-11 12:22:21 +08:00
Tyler Stillwater fec06da6a3 Add BeginTx for parity with sql.DB.BeginTx (#2227) 2019-06-11 12:22:21 +08:00
Hylke Visser cf9b85ed90 Don't set primary key's HasDefaultValue to true (#2127) 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
Miguel Moll 9127f7d86e Handle error when beginning transaction (#2489) 2019-06-11 12:22:20 +08:00
Ruben de Vries 712c465560 add an override on the DB instance instead of using the global NowFunc. (#2142) 2019-06-10 20:45:42 +08:00
Tyler Stillwater af01854d3e Add BeginTx for parity with sql.DB.BeginTx (#2227) 2019-06-10 20:33:20 +08:00
Hylke Visser ac78f05986 Don't set primary key's HasDefaultValue to true (#2127) 2019-06-10 20:24:05 +08:00
Adam S Levy 44d3060254 Add RollbackUnlessCommitted() (#2126) 2019-06-10 20:19:39 +08:00
John Barker ea12400190 Don't AddError for Rollback on ErrTxDone (#2434) 2019-06-10 20:14:44 +08:00