Commit Graph

246 Commits

Author SHA1 Message Date
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
Jinzhu 81c00fdc8f Don't add duplicated error 2015-08-18 11:09:03 +08:00
Jinzhu dd0d4d931f Add errorsInterface 2015-08-14 14:53:26 +08:00
Jinzhu 0996ddb604 Rename Errors to GetErrors 2015-08-14 12:29:53 +08:00
Jinzhu 309740983e Add Errors 2015-08-14 11:04:05 +08:00
Jay Taylor 17917d49d8 Reverted to original `NewRecord' func as per @jinzhu's feedback. 2015-08-12 09:32:18 -07:00
Jay Taylor 526fff01b7 Merge branch 'jay/current_database' into jay/ddl-errors 2015-08-11 09:05:53 -07:00
Jay Taylor beeb040c62 Reworked CurrentDatabase API to return the name instead of `*gorm.DB'. 2015-08-11 08:59:59 -07:00
Jay Taylor da31f58607 Ensure DDL dialect queries propagate error states to descendent scopes.
Includes relevant unit-test.

Branched from jay/current_database (please merge that branch first!).
2015-08-08 14:25:15 -07:00
Jay Taylor 70725f9d77 `CurrentDatabase' determines current dbname by querying the database.
Preserves the gorm-style query API.
2015-08-08 08:56:23 -07:00
Jinzhu 6b8f2fcab8 Send a ping to make sure the database connection is alive, thanks @pariz 2015-08-02 07:37:33 +08:00
Jinzhu a7762ea7d6 Return error happend in Create/Update when using FirstOrCreate 2015-08-01 12:00:35 +08:00
Jinzhu 6f30170fec Use copy logger into itself instead of using parent's 2015-08-01 11:12:39 +08:00
Jinzhu dc428d2364 Fix compile error for association 2015-07-30 17:26:10 +08:00
Jinzhu a29230c86f multpile foreign keys 2015-07-30 16:23:51 +08:00
Jinzhu 2a1d64c3e0 Return cloned db instance for AddForeignKey 2015-06-24 14:09:59 +08:00
Jay Taylor c2c1dd1fc8 Fix errors being inaccessible due to errors being set on different *DB instance than what is returned. 2015-06-23 15:29:44 -07:00
Jinzhu dbedca4e5f Don't run auto migrate if join table doesn't exist 2015-06-23 14:19:59 +08:00
Jinzhu b96ca76e59 Set table name handler 2015-05-27 12:19:48 +08:00
Jinzhu c2dda88f9a Use Get to replace InstanceGet 2015-05-19 16:58:33 +08:00
Jinzhu ef4299b398 Add RowQuery callback 2015-04-17 18:27:20 +08:00
Jinzhu 4fbc9d2a8f Remove foundationdb from tests all script because it is not downloadable from offical site 2015-04-17 14:52:59 +08:00
Jinzhu e2eef50fb4 Add SetTableNameHandler 2015-04-08 14:56:03 +08:00
Jinzhu 03966a1e20 Merge pull request #436 from jaytaylor/master
FoundationDB dialect integration
2015-03-30 14:55:50 +08:00
Jay Taylor ab48cd222a `UpdateColumns(...)` no longer triggers save of associated records. 2015-03-28 14:15:12 -07:00
Jay Taylor dcc06e22f7 FoundationDB dialect layer and compatibility updates. 2015-03-24 10:35:19 -07:00
Jinzhu 7d16055a5d Don't use instance setting for order_by_primary_key 2015-03-23 11:07:39 +08:00
Jinzhu 94a5ebe5b4 Refactor JoinTableHandler 2015-03-20 11:22:14 +08:00
Jinzhu 44b106c8e2 Fix tests 2015-03-19 18:23:54 +08:00
Jinzhu c13e2f18f8 New JoinTableHandler 2015-03-18 11:47:11 +08:00
Jinzhu 5d52826b3d Create with Omit 2015-03-12 18:01:27 +08:00
Jinzhu da7830ea50 Add SelectAttrs, OmitAttrs 2015-03-12 15:50:38 +08:00
Jinzhu 94adc3e1d8 Export Unscoped Field for search 2015-03-12 15:01:59 +08:00
Jinzhu 6e5d46bf37 Refactor Search API 2015-03-12 14:47:07 +08:00
Jinzhu df33db6ff9 Save cached model structs globally 2015-03-11 18:33:50 +08:00
Jinzhu 49454839bd Support Multi primary keys 2015-03-11 11:28:30 +08:00
Jinzhu 287ae22ca6 Add method New back 2015-03-04 13:56:47 +08:00
Jinzhu 34997385b0 Add HasIndex method for dialect interface 2015-03-02 23:02:40 +08:00
Jinzhu 22b1a93e03 Add JoinTableHandler test 2015-02-28 14:16:51 +08:00
Jinzhu 6d64e6837b Add JoinTableHandler 2015-02-28 12:05:14 +08:00
Jinzhu 33e6b14632 Clear value from db after set table name 2015-02-26 16:08:26 +08:00
Jinzhu ce72988e96 Refactoring API for plugin system 2015-02-26 14:40:30 +08:00
Vytautas Šaltenis 59f32f605c Fix a few typos 2015-02-24 21:17:35 +02:00
Jinzhu 73a0401678 Cache generated model structs 2015-02-17 23:18:12 +08:00
Jinzhu 0b32041135 Review and Refactor 2015-02-17 22:55:14 +08:00
Jinzhu 139b9a37e7 Merge branch 'master' into refactor 2015-02-17 08:38:32 +08:00
Jinzhu 73b6f0eace Linting according to golint 2015-02-17 08:34:01 +08:00
Jinzhu 3a73206010 Refactor model struct 2015-02-16 16:35:26 +08:00
Jinzhu 6864d5e5bd Add polymorphic_test.go 2015-02-13 11:26:02 +08:00
Jinzhu 6dc33d6d94 Merge pull request #360 from sendyhalim/scope-add-foreignkey
Add Scope.addForeignKey()
2015-02-11 19:35:57 +08:00
Jinzhu dd635a17c2 Preload belongs_to, has_one, has_many relations 2015-02-11 13:43:53 +08:00
Jinzhu 3b784c37c4 First try for the Preload feature 2015-02-11 09:47:10 +08:00
sendyHalim a8b3e8d3e2 Add Scope.addForeignKey() 2015-02-07 18:04:10 +07:00
Jinzhu 5330572c25 Fix Exec with raw string 2015-01-20 14:55:38 +08:00
Jinzhu 3500dfa1b6 expose db.New as API 2015-01-06 15:11:41 +08:00
jnfeinstein 8b451f0084 Add support for polymorphic relationships using the POLYMORPHIC setting.
This commit adds support for two settings:

FOREIGNTYPE - A field that is used to store the type of the owner.

POLYMORPHIC - A shortcut to set FOREIGNKEY and FOREIGNTYPE to the same
value suffixed by "Id" and "Type" respectively.

The type is stored as the table name, which I thought might be useful
for other queries.

The biggest gotcha of this commit is that I flipped the definition of
has_one and belongs_to. gorm is very flexible such that it didn't
really care if it was a has_one or belongs_to, and can pretty much
determine it at runtime. For the sake of the error, I had to define
one of them as belongs_to, and I chose the one with the fields as
the belongs_to, like ActiveRecord. The error could probably be
genericized to "gorm cannot determine type", but I think it's nicer
to tell people DONT DO PATTERN XYZ CAUSE IT WONT WORK. Functionally,
it doesn't matter.
2014-11-25 21:35:47 -08:00
Jinzhu a4e0ef6509 Refactor reuse existing database connection 2014-11-25 15:21:28 +08:00
jnfeinstein 1d6b59f223 Allow .Open to reuse existing database connections.
This commit allows you to pass a string or an existing database
connection as the source for gorm. The dialect is still required
because a) there is no common reference to it as far as i know, and
b) gorm allows the dialect to differ from the driver. So, for the sake
of simplicity, you still have to specity the dialect.

This is useful if you have an existing transaction, but still
want to use gorm to format your queries.

This is dependent on the defintion of DB in pkg database/sql having
the field 'dsn', which is the database source, obtained via reflect.
2014-11-25 15:21:28 +08:00
Jinzhu e9684db42a Show error message if not using addressable value for auto migration 2014-11-25 13:44:14 +08:00
jnfeinstein 429a100856 Add additional methods of specifying the 'select' portion of a query.
This commit adds more ways of specifying selects:

-) You can now pass in a []string.  This is mostly for convenience,
since you may want to dynamically create a list of fields to be
selected.

-) You can now use variables.  This is important because a select
could take user input.  For example, finding a MAX between a record
and a given number could be easily done using select, and then
you don't have to process anything in backend logic.  This is also
necessary to use postgres text search capabilities (which actaully
play nicely with the rest of gorm).

-) You can now chain select calls.  This could be useful in
conjunction with gorm's scopes functionality.
2014-11-17 07:36:26 -05:00
Jinzhu a29ac54e48 Limit condition should not be inherited by following queries 2014-10-28 17:18:11 +08:00
Jinzhu 5eeff5d38f Fix some errors for the mssql support pull request 2014-09-19 21:49:04 +08:00
Joel Trost 6b7d0879c5 Ran gofmt and removed panic statements
Unnecessary panics in create_test and delete_test removed
2014-09-16 14:24:55 -07:00
Joel Trost f79e1a2ef6 GORM support for MSSQL, passes all tests 2014-09-16 14:21:35 -07:00
Jinzhu b2360c11da Add Fields for embedded struct 2014-08-30 21:42:35 +08:00
Robert B Gordon 94aa843830 Add HasTable() 2014-08-29 00:28:54 -05:00
Jinzhu 5347765bd3 Merge pull request #206 from cihangir/master
gorm: added ability to change the time.now format
2014-08-27 16:19:55 +08:00
Jinzhu 922395c965 Add InstantSet for DB 2014-08-25 17:10:46 +08:00
Jinzhu 3af077ac46 Refact First, Last to make it possible to reset table name in Plugin 2014-08-25 16:41:26 +08:00
Cihangir SAVAS 4e90fbf4e8 gorm: added ability to change the time.now format 2014-08-23 01:00:04 -07:00
Jinzhu 39ac95adbb Add InstanceSet, InstanceGet fomr Scope 2014-08-20 17:05:02 +08:00
Jinzhu 9012c9ea09 Add Set, Get method for DB 2014-08-20 16:25:01 +08:00
Jinzhu 14fdbdd965 AutoMigrate accepts structs 2014-08-20 11:56:39 +08:00
Shirou WAKAYAMA 5ad9306146 Add DropTableIfExists. 2014-08-05 23:14:40 +09:00
Jinzhu 4d98c8c0bc Specify database dialect when open database, fixes #169 2014-08-05 10:34:41 +08:00
Benjamin Ruston d699c85486 Use fmt.Errorf 2014-08-04 19:54:05 +01:00
Jinzhu 90106d82c5 Export Relationship 2014-07-31 14:38:16 +08:00
Jinzhu 2356182ea7 Rename joinTable to relationship 2014-07-30 20:59:52 +08:00
Jinzhu e1e68debdc improve association 2014-07-30 20:48:36 +08:00
Jinzhu ba95de5c50 Rename relations to associations 2014-07-30 14:30:21 +08:00
Jinzhu d7400c2df4 Don't sort by primary key if it doesn't exist in First/Last 2014-07-29 18:29:03 +08:00
Jinzhu 2bffb43138 Write stub code for Many2Many 2014-07-29 17:28:10 +08:00
Jinzhu 11dc47587c Support inline condition when Delete 2014-07-24 18:30:12 +08:00
Jinzhu 1c1df2318c Fix exception for FirstOrCreate when search condition is nil 2014-07-01 15:55:19 +08:00
Jinzhu 6c5b95e2b2 Return query error in FirstOrInit and FirstOrCreate 2014-06-23 20:10:54 +08:00
Vladimir Garvardt d2e526bc2d db.Create() for force insert with predefined primary key 2014-06-12 00:51:43 +04:00