forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
|
||
- 自动生成 CRUD 和 DIY 方法 | ||
- 自动根据表结构生成模型(model)代码 | ||
- 事务、嵌套事务、保存点、回滚事务点 | ||
- 完全兼容 GORM | ||
- 更安全、更友好 | ||
- 多种生成代码模式 | ||
|
@@ -94,6 +95,7 @@ | |
- [预加载](#preloading) | ||
- [预加载(Preload)](#preload) | ||
- [预加载全部数据(Preload All)](#preload-all) | ||
- [预加载指定列](#preload-with-select) | ||
- [根据条件预加载](#preload-with-conditions) | ||
- [嵌套预加载](#nested-preloading) | ||
- [更新](#update) | ||
|
@@ -216,6 +218,7 @@ demo | |
│ └── query # generated code's directory | ||
| ├── user.gen.go # generated code for user | ||
│ └── gen.go # generated code | ||
| └── user.gen_test.go # generated unit test | ||
├── biz | ||
│ └── query.go # call function in dal/gorm_generated.go and query databases | ||
├── config | ||
|
@@ -257,6 +260,7 @@ FieldType // specify field type | |
FieldTypeReg // specify field type (match with regexp) | ||
FieldTag // specify gorm and json tag | ||
FieldJSONTag // specify json tag | ||
FieldJSONTagWithNS // specify new tag with name strategy | ||
FieldGORMTag // specify gorm tag | ||
FieldNewTag // append new tag | ||
FieldNewTagWithNS // specify new tag with name strategy | ||
|
@@ -729,6 +733,7 @@ c := q.CreditCard | |
type Result struct { | ||
Name string | ||
Email string | ||
ID int64 | ||
} | ||
|
||
var result Result | ||
|
@@ -1328,6 +1333,8 @@ u.WithContext(ctx).Omit(field.AssociationFields).Create(&user) | |
|
||
###### <span id="find-associations">查询关联</span> | ||
|
||
查询匹配的关联 | ||
|
||
```go | ||
u := query.Use(db).User | ||
|
||
|
@@ -1412,6 +1419,8 @@ db.Select(field.AssociationsFields).Delete(&user) | |
|
||
##### <span id="preloading">预加载</span> | ||
|
||
此功能目前仅支持现有模型 | ||
|
||
###### <span id="preload">预加载(Preload)</span> | ||
|
||
GEN 允许使用 `Preload` 在其他 SQL 中预先加载关系,例如: | ||
|
@@ -1586,7 +1595,7 @@ u.WithContext(ctx).Where(u.Activate.Is(true)).UpdateSimple(u.Age.Value(17), u.Nu | |
// UPDATE users SET age=17, number=0, birthday=NULL, updated_at='2013-11-17 21:34:10' WHERE active=true; | ||
``` | ||
|
||
> **NOTE** When update with struct, GEN will only update non-zero fields, you might want to use `map` to update attributes or use `Select` to specify fields to update | ||
> **注意** 当通过 struct 更新的时候,GEN 将只会更新其非零值的字段,你可能需要用 `map` 去更新属性,或者用 `select` 去明确指定哪些字段是需要被更新的 | ||
##### <span id="update-selected-fields">更新指定字段</span> | ||
|
||
|
@@ -1869,7 +1878,6 @@ select * from @@table where | |
|
||
##### <span id="method-interface-example">方法接口示例</span> | ||
|
||
|
||
```go | ||
type Method interface { | ||
// Where("name=@name and age=@age") | ||
|
@@ -1909,11 +1917,10 @@ type Method interface { | |
// {{for _,user:=range users}} | ||
// {{if user.Age >18} | ||
// OR [email protected] | ||
// {{end}} | ||
// {{end}} | ||
// {{end}} | ||
// {{end}} | ||
FindByOrList(cond bool, id int, key, value string) ([]gen.T, error) | ||
|
||
FindByOrList(users []gen.T) ([]gen.T, error) | ||
} | ||
``` | ||
|
||
|
@@ -1925,7 +1932,6 @@ type Method interface { | |
|
||
一个测试用例包含输入和期望结果,输入应和对应的方法参数匹配,期望应和对应的方法返回值相匹配。这将在测试中被断言为 “**Equal(相等)**”。 | ||
|
||
|
||
```go | ||
package query | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters