Commit Graph

231 Commits

Author SHA1 Message Date
Jinzhu 45fc640bf3 Merge pull request #1252 from slockij/block-global-update-delete
Block global updates / deletes
2016-11-10 08:45:29 +08:00
Jinzhu 53d09952be Fix AddError for DB 2016-11-09 10:22:42 +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
Caleb Thompson c063624c91
Make gorm.Errors available for use outside gorm
gorm.Errors, which usefully implements `error` for an `[]error` as
returned by `DB.GetError()` was already exported, but because it used a
private field `errors`, it was not able to be created due to the
compile-time error:

    implicit assignment of unexported field 'errors' in gorm.Errors literal

The trivial solution would be to export the `errors` field on
`gorm.Errors`, but this led to the issue that the common pattern of
checking `err != nil` failed because a struct{error: nil} != nil.

We can take advantage of type aliasing here to make Errors an []error,
which can in fact be nil and would pass `err != nil` on the happy path.

* Remove `(Errors) GetErrors()`, as it's less useful when Errors is an
  []error which can be iterated over. While this is technically a
  breaking change, we never expose an Errors and its difficult to build
  one (it can be done with the existing `(Errors) Add(error)`), but
  awkwardly. This removal can be reverted without issue and we can make
  it an identity method, but it seemed an opportune time to reduce API
  surface area on something that likely isn't used.
* Remove errorsInterface, as it's not useful without `(Errors)
  GetErrors()`
* Change `(*Errors) Add(error)` => `(Errors) Add(error...) Errors`
  because we can't modify even a *Errors when it's a type alias. This is
  more idiomatic as it follows the pattern of `slice = append(slice,
  element)` Go developers are familiar with.
2016-10-25 11:22:50 -05: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
Baiju Muthukadan 0d54677e13 if no arguments, return error at once 2016-10-07 17:12:29 +05:30
cloudaice 7dcd80ddf9 fix goroutine leak while calling db.Ping() error 2016-09-18 14:26:16 +08:00
Jinzhu 6732a50dfb Get Dialect of DB 2016-09-13 07:41:42 +08:00
Jinzhu 02f6ae3c4e If failed to update current record with Save, try to create a new one 2016-09-07 21:54:19 +08:00
Jinzhu c1c4f9f86e Add ORDER BY sql expression support 2016-06-28 11:15:42 +08:00
Jay Taylor 1485f4bce9 Use validated interface{} for limit/offset values to ensure values greater than
max 32-bit integer are addressable, and in a backwards-compatible way.
2016-06-23 06:29:51 -07:00
Jinzhu f926dd9f9f Revert "Use int64 for limit/offset values to ensure values > 32-bit int are addressable." 2016-06-16 16:31:50 +08:00
Jay Taylor 9b0fb2feb9 Use int64 for limit/offset values to ensure values greater than max 32-bit
integer are addressable.
2016-06-08 17:03:22 -07:00
Jinzhu 021d7b3314 Fix migrate indexes with CreateTable, AutoMigrate for soft delete 2016-03-17 18:12:25 +08:00
Jinzhu 8c099e0945 Fix AddUniqueIndex with soft delete 2016-03-17 18:09:21 +08:00
Jinzhu 846a2d401a Fix scan columns with same name 2016-03-10 17:13:48 +08:00
Jinzhu 8de97c2883 Refactor Scope updatedAttrsWithValues 2016-03-09 16:45:53 +08:00
Jinzhu d08894cd69 Rename test files 2016-03-08 22:00:15 +08:00
Jinzhu 946909f1e8 Add DropTableIfExists back 2016-03-07 21:34:14 +08:00
Jinzhu 88184a989e Update godoc 2016-03-07 21:09:05 +08:00
Jinzhu 779c4d436e Refactor based on golint 2016-03-07 18:43:15 +08:00
Jinzhu ec110657da Refactor based on golint 2016-03-07 17:49:55 +08:00
Jinzhu 3055bad1e8 scope.Fields() return slice of *Field 2016-03-07 14:25:41 +08:00
Jinzhu 2522f03c1f Set identity insert on after create transaction, close #841 2016-03-05 19:22:33 +08:00
Jinzhu 6bd0862811 Only update non blank fields that has been changed 2016-02-18 23:17:35 +08:00
Jinzhu 115789960a Joins support parameters, close #673 2016-02-16 22:48:26 +08:00
Jinzhu 4e8370e18b Refactor dialect 2016-02-15 14:59:15 +08:00
Jinzhu 6546ec3b5e Scan Rows into struct, fix #59 2016-02-14 23:29:06 +08:00
Jinzhu f4456e139e Register dialects 2016-02-14 18:06:42 +08:00
Jinzhu 86b4b20278 Merge branch 'master' into v1.0_dev 2016-02-14 14:18:35 +08:00
Jinzhu 77928d8373 Check argument is string or not in HasTable 2016-02-14 14:17:25 +08:00
Jinzhu d92c5db9e7 Refactor dialect 2016-01-19 13:11:11 +08:00
Jinzhu e159ca1914 Refactor dialect 2016-01-18 20:32:52 +08:00
Jinzhu e38b1e0948 Remove uncessary NeedPtr method 2016-01-17 17:12:19 +08:00
Jinzhu 8e2aaa92c9 Rename Callbacks to Callback 2016-01-16 21:55:00 +08:00
Jinzhu f1237e4fe9 Refactor Callback 2016-01-16 21:46:57 +08:00
Jinzhu dc23ae63bf Keep refactoring association mode 2016-01-16 17:29:39 +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
Jinzhu 341d047aa7 Rollback to old Unscoped API 2016-01-12 15:27:25 +08:00
Jinzhu 43e9035dad Fix Association Count with Soft Delete 2016-01-12 13:56:41 +08:00
Jinzhu f574429f5e Return pointer when Open 2016-01-10 21:26:55 +08:00
Jinzhu aa55bd3fd2 Add more tests for customized foreign keys for many2many relations 2016-01-03 17:20:24 +08:00
Jinzhu 4e45e6dc2d Use field.TagSettings 2016-01-03 10:00:18 +08:00
Jinzhu 19b85b1f17 Compatible with both gorm, sql tag 2016-01-03 09:52:27 +08:00
Jinzhu e541ca5cdf Fix DropTableIfExists with string 2015-12-16 21:00:56 +08:00
Athurg Feng f1decc2c3e Fix FirstOrXXX access invalid memory address
*DB is cloned, we should ALWAYS use the cloned pointer instead of original one.
2015-10-12 22:38:41 +08:00
Jinzhu 4da2c28d4d Fix data race warning when get cached model struct 2015-10-01 07:09:00 +08:00
Jinzhu 1d5f5f43f3 Support create/drop multiple tables 2015-08-26 11:54:07 +08:00