Commit Graph

260 Commits

Author SHA1 Message Date
Momo733 1c62bf1e57
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-04-13 14:23:35 +08:00
kuangzhiqiang d239c4cab8 error log show trace file (#2296) 2019-03-10 20:03:55 +08:00
Jinzhu d7ef7871a4 Fix tests 2019-03-10 19:33:49 +08:00
李鹏 ac6c89ec0c search不需要再clone,dbClone内的search已经是一个全新的了 (#2179) 2019-01-02 21:25:37 +08:00
Sai 5ad6f621e6 logMode codes more readable (#2216) 2018-12-13 21:04:51 +08:00
Eyal Posener 123d4f50ef lock TagSettings structure when modified (#1796)
The map is modified in different places in the code which results in race conditions
on execution.
This commit locks the map with read-write lock when it is modified
2018-09-10 07:11:00 +08:00
gstvg 282f11af19 Support only preloading (#1926)
* add support for only preloading relations on an already populated model

* Update callback_query.go

comments
2018-09-10 06:52:32 +08:00
Aaron Leung 73e7561e20 Use sync.Map for DB.values (#2064)
* Replace the regular map with a sync.Map to avoid fatal concurrent map reads/writes

* fix the formatting
2018-09-10 06:26:29 +08:00
Artemij Shepelev 0e04d414d5 Race fix. Changes modelStructsMap implementation from map with mutex to sync.Map (#2022)
* fix (https://github.com/jinzhu/gorm/issues/1407)

* changed map with mutex to sync.Map (https://github.com/jinzhu/gorm/issues/1407)

* removed newModelStructsMap func

* commit to rerun pipeline, comment changed
2018-08-19 07:09:21 +08:00
antness d68403b29d do not close wrapped *sql.DB (#1985) 2018-07-27 07:43:09 +08:00
Kevin ac3ec858a6 Edit DB.clone(), DB.Dialect(), and Scope.Dialect() preserve transactions (#1939)
* Edit DB.clone(), DB.Dialect(), and Scope.Dialect() preserve transactions.

* Adds a test case for tables creations and autoMigrate in the same transaction.
2018-07-27 07:35:53 +08:00
lrita a58b98acee Do not panic if Begin().Error was ignored (#1830) (#1881) 2018-05-12 01:28:15 -05: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
Giuseppe 919c6db4f8 Do not panic if Begin().Error was ignored (#1830) 2018-04-16 09:18:51 -05:00
Jinzhu 48a20a6e9f Add SubQuery method 2018-02-22 12:04:12 +08:00
Jinzhu fe3c94cd2d Add Take method, close #1228 2018-02-13 09:18:42 +08:00
Jinzhu 7a8c2bbff8 Refactor build SQL condition 2018-02-12 00:06:31 +08:00
Emil Davtyan c0359226dc Removed unnecessary cloning. (#1462)
`NewScope` clones `DB` no need to chain a call to clone with `NewScope`.
2018-02-10 19:31:55 +08:00
Amit Yadav 0e1cb6ece9 Add support to remove foreign key constraints (#1686) 2018-02-09 22:20:26 +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
liu-xuewen 10e217e2bc Print affected rows (#1541)
* fix better

* add the rows number that the sql result affected or returned
2017-07-23 16:04:22 +08:00
Jinzhu b21c0bef9b Merge pull request #1412 from slayer/master
prevent nil pointer dereference on closed connection
2017-04-18 22:53:27 +08:00
Emil Davtyan 5ed4c3f290 Allow open to take transaction.
Need to skip the ping, otherwise results in a nil dereference.
2017-04-18 15:33:13 +02:00
Vladislav Moskovets 72a60c5df4 prevent nil pointer dereference on closed connection 2017-03-31 14:26:51 +03:00
Russ Egan 45f1a95051 Replace all use of *sql.DB with sqlCommon
Exporting sqlCommon as SQLCommon.

This allows passing alternate implementations of the database connection, or wrapping the connection with middleware.  This change didn't change any usages of the database variables.  All usages were already only using the functions defined in SQLCommon.

This does cause a breaking change in Dialect, since *sql.DB was referenced in the interface.
2017-03-14 17:02:14 -04:00
Jinzhu 1558522aaa Refactor 2017-02-05 15:10:28 +08:00
Maxime Song 58cbc9c4b5 fix typo 2017-01-04 15:53:49 +08:00
Jinzhu 0f2ceb5a77 Add gorm:association:source for association operations for plugins to extend GORM 2016-12-05 18:30:07 +08:00
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