Commit Graph

195 Commits

Author SHA1 Message Date
Jinzhu 802104cc7c Use BuildKeyName to build db's index name 2018-02-02 22:01:31 +08:00
Jinzhu 630c12b549 Refactor #1693 2018-01-31 17:14:21 +08:00
Wing Gao 26262ef9bb autoIndex should throw an error on failed 2017-11-28 13:05:48 +08:00
Horacio Duran 3a9e91ab37 Correct ModifyColumn SQL syntax. (#1614)
* Correct ModifyColumn SQL syntax.

The generated SQL for ModifyColumn was:

`ALTER TABLE "tablename" MODIFY "columname" type`

But should have been:

`ALTER TABLE "tablename" ALTER COLUMN "columname" TYPE type`

since Modify does not seem to be entirely compatible with all Engines

* Test ModifyColumn

* Skip ModifyColumnType test on incompatible DBs

Some DB Engines don't fully support alter table so we skip
when the dialect does not correspond to one of the ones that
are known to support it.
2017-09-28 22:48:21 +08:00
Jinzhu e5432b14d2 Add QueryExpr, thanks @ManReinsp for PR #1548 2017-08-11 18:41:04 +08:00
Ivan Valkov 2a1463811e Allow use number as column name (#1517)
* Updated scope.go to always quote when adding index

I am using numbers for column names (to be compatible with protobuf) and adding unique index to them does not work since they are not quoted. I do not see a reason to check if the column name is a string in order to quote it. Correct me if I am wrong.

* Updated the columnRegexp to include decimals

* Update scope.go
2017-07-03 21:49:54 +08:00
Jinzhu 2a041971f9 Change bind var to 24652$ to avoid possible confliction 2017-04-18 16:13:02 +08:00
Jinzhu 66d5b42ee9 Add error if exists after parse raw query results, fix #1398 2017-03-24 09:28:06 +08: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 e4b130d2d7 Fix customize DeletedAt's column name 2017-02-01 21:33:36 +08:00
Jinzhu c62e9bcabe Query Row, Rows inside RowQuery callbacks 2017-01-15 18:03:12 +08:00
Geofrey Ernest eb0880e710 Fix *Scope.buildNotCondition
this fixes the logic of handling empty slice of int family in a query i.e something linke `[]int64{}`

This code snipped doesn't look like it was intended to be this way

```
	if reflect.ValueOf(value).Len() > 0 {
			str = fmt.Sprintf("(%v.%v NOT IN (?))", scope.QuotedTableName(), scope.Quote(primaryKey))
			clause["args"] = []interface{}{value}
		}
		return ""
```

The `return ""` is always guaranteed to be executed regardless of whether the length of value is greater than 0. I believe the intended behavior is to return  `""` when the length of value is zero.
2017-01-05 10:38:39 +03:00
Xavier Sandal 5a4dca7645 Compile regexp ahead of time
Signed-off-by: Xavier Sandal <sandalwing@sandalwing.com>
2016-12-19 22:36:13 -05:00
Jinzhu 0f2ceb5a77 Add gorm:association:source for association operations for plugins to extend GORM 2016-12-05 18:30:07 +08:00
Jinzhu eb06255b66 Skip order sql when quering with distinct 2016-12-01 16:16:20 +08:00
Jinzhu 066abcef40 Merge pull request #1132 from zardak/preload-dedupe 2016-11-10 09:33:15 +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 f2fe351aa0 Merge pull request #1243 from smacker/raw_first_last
db.Raw().First() makes wrong sql fix #1214
2016-11-03 21:45:29 +08:00
Jinzhu 4a540f3ac8 Add tag to support skip nested save for associations 2016-10-27 10:31:46 +08:00
smacker cf7fbb56d5 db.Raw().First() makes wrong sql fix #1214 2016-10-26 21:32:27 +07:00
Jinzhu 56a7d1b69e Change query's prefix table for generated conditions 2016-10-26 17:35:51 +08:00
Jinzhu 39165d4980 Refactor named value support for PolymorphicType 2016-10-07 22:19:28 +08:00
slockij 1413e55339 Add named value for PolymorphicType (to replace scope.TableName) 2016-09-28 22:44:43 +02:00
Jinzhu 041cd3dd31 Fix scan ignored fields, close #1117 2016-09-13 09:29:36 +08:00
Jinzhu 35a2a004d8 Strict select argument check for Count 2016-08-15 21:28:07 +08:00
Jinzhu 2f27f0f27f Fix TestUpdateDecodeVirtualAttributes 2016-08-14 16:13:50 +08:00
elgris fb09befb9b Adds processing of ignored fields on Update 2016-08-14 16:12:57 +08:00
Jinzhu 34e75afb42 Support specify count select argument 2016-08-14 15:15:09 +08:00
Jinzhu fde205f758 Refactor joining multiple tables with the same fields 2016-08-13 21:23:18 +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 ca46038cb4 Fix preload duplicates has many related objects 2016-07-10 21:34:37 +08:00
Jinzhu c1c4f9f86e Add ORDER BY sql expression support 2016-06-28 11:15:42 +08:00
Michael Goff e7f00bd2cd Add support for multiple indexes seperated by commas for issue #884 2016-06-15 16:06:22 -07:00
Nikola Kovacs 6eb73ae654 Fix too long foreign key names in mysql.
The dialect must define its own foreign key generator method.
The previous default is available as a method on gorm.DefaultForeignKeyNamer
and can be embedded in other dialects.
The mysql dialect uses the first 24 characters plus an sha1 hash of the
full key name if the key name is more than 64 characters.
2016-05-22 00:13:26 +02:00
Jinzhu 4786e830d6 Fix create join table 2016-05-09 22:32:33 +08:00
Jinzhu 5174cc5c24 Only get address from non pointer when call method, fix #912 2016-04-04 22:49:28 +08:00
Jinzhu 9fd05d1bad Print warning message when using unaddressable value with Update 2016-04-04 21:33:11 +08:00
Jinzhu c49e68fac2 Make Update works with unaddressable value 2016-04-04 20:57:42 +08:00
Jinzhu 2530dcbccd Quote order column name, fix #918 2016-03-23 10:29:52 +08:00
Jinzhu 83002c4d5f Include default search attributes when query with Join, close #906 2016-03-14 08:05:45 +08:00
Jinzhu 7c43d9fc36 Fix scan columns with same name 2016-03-10 17:35:19 +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 a0aa21aec5 Refactor 2016-03-08 22:29:58 +08:00
Jinzhu d08894cd69 Rename test files 2016-03-08 22:00:15 +08:00
Jinzhu 88184a989e Update godoc 2016-03-07 21:09:05 +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 6bd0862811 Only update non blank fields that has been changed 2016-02-18 23:17:35 +08:00
Jinzhu d92c5db9e7 Refactor dialect 2016-01-19 13:11:11 +08:00