diff --git a/pages/ar_SA/gen/database_to_structs.md b/pages/ar_SA/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/ar_SA/gen/database_to_structs.md +++ b/pages/ar_SA/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/az_AZ/gen/database_to_structs.md b/pages/az_AZ/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/az_AZ/gen/database_to_structs.md +++ b/pages/az_AZ/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/de_DE/gen/database_to_structs.md b/pages/de_DE/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/de_DE/gen/database_to_structs.md +++ b/pages/de_DE/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/es_ES/gen/database_to_structs.md b/pages/es_ES/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/es_ES/gen/database_to_structs.md +++ b/pages/es_ES/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/fa_IR/gen/database_to_structs.md b/pages/fa_IR/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/fa_IR/gen/database_to_structs.md +++ b/pages/fa_IR/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/fr_FR/gen/database_to_structs.md b/pages/fr_FR/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/fr_FR/gen/database_to_structs.md +++ b/pages/fr_FR/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/hi_IN/gen/database_to_structs.md b/pages/hi_IN/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/hi_IN/gen/database_to_structs.md +++ b/pages/hi_IN/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/id_ID/gen/database_to_structs.md b/pages/id_ID/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/id_ID/gen/database_to_structs.md +++ b/pages/id_ID/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/it_IT/gen/database_to_structs.md b/pages/it_IT/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/it_IT/gen/database_to_structs.md +++ b/pages/it_IT/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/ja_JP/gen/database_to_structs.md b/pages/ja_JP/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/ja_JP/gen/database_to_structs.md +++ b/pages/ja_JP/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/ko_KR/gen/database_to_structs.md b/pages/ko_KR/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/ko_KR/gen/database_to_structs.md +++ b/pages/ko_KR/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/pl_PL/gen/database_to_structs.md b/pages/pl_PL/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/pl_PL/gen/database_to_structs.md +++ b/pages/pl_PL/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/pt_BR/gen/database_to_structs.md b/pages/pt_BR/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/pt_BR/gen/database_to_structs.md +++ b/pages/pt_BR/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/ru_RU/gen/associations.md b/pages/ru_RU/gen/associations.md index 7a70f89561b..08cc7fde4b1 100644 --- a/pages/ru_RU/gen/associations.md +++ b/pages/ru_RU/gen/associations.md @@ -3,11 +3,11 @@ title: Associations layout: page --- -GEN will auto-save associations as GORM do. The relationships (BelongsTo/HasOne/HasMany/Many2Many) reuse GORM's tag. This feature only support exist model for now. +GEN will auto-save associations as GORM do. Отношения (один к одному, один ко многим, многие к одному, многие ко многим) повторно используют тег GORM. На данный момент эта функциональность поддерживает только существующие модели. -## Relation +## Отношения -There are 4 kind of relationship. +Есть 4 вида отношений. ```go const ( @@ -36,7 +36,7 @@ type CreditCard struct { } ``` -GEN will detect model's associations: +GEN обнаружит обратные ссылки: ```go // specify model diff --git a/pages/ru_RU/gen/database_to_structs.md b/pages/ru_RU/gen/database_to_structs.md index e6622777358..7e896b7c720 100644 --- a/pages/ru_RU/gen/database_to_structs.md +++ b/pages/ru_RU/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/tr_TR/gen/database_to_structs.md b/pages/tr_TR/gen/database_to_structs.md index b40bd7e7ec5..a920294d713 100644 --- a/pages/tr_TR/gen/database_to_structs.md +++ b/pages/tr_TR/gen/database_to_structs.md @@ -34,6 +34,10 @@ func main() { // Generate struct `User` based on table `users` and generating options g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + ) g.ApplyBasic( // Generate structs from all tables of current database diff --git a/pages/zh_CN/docs/context.md b/pages/zh_CN/docs/context.md index e849d33a376..ad776a42ef4 100644 --- a/pages/zh_CN/docs/context.md +++ b/pages/zh_CN/docs/context.md @@ -1,9 +1,9 @@ --- -title: Context +title: 上下文 layout: page --- -GORM's context support, enabled by the `WithContext` method, is a powerful feature that enhances the flexibility and control of database operations in Go applications. It allows for context management across different operational modes, timeout settings, and even integration into hooks/callbacks and middlewares. Let's delve into these various aspects: +GORM 的上下文支持由 `WithContext` 方法启用,是一项强大的功能,可以增强 Go 应用程序中数据库操作的灵活性和控制力。 它允许在不同的操作模式、超时设置以及甚至集成到钩子/回调和中间件中进行上下文管理。 让我们从不同方面深入了解: ### 单会话模式 diff --git a/pages/zh_CN/gen/database_to_structs.md b/pages/zh_CN/gen/database_to_structs.md index 7aed8e27219..f6aeecc3c37 100644 --- a/pages/zh_CN/gen/database_to_structs.md +++ b/pages/zh_CN/gen/database_to_structs.md @@ -15,30 +15,35 @@ import "gorm.io/gen" func main() { g := gen.NewGenerator(gen.Config{ OutPath: "../query", - Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, // 生成模式 + Mode: gen.WithoutContext|gen.WithDefaultQuery|gen.WithQueryInterface, // generate mode }) // gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local")) g.UseDB(gormdb) // reuse your gorm db - // 按照约定为结构体 `model.User` 生成类型安全的 DAO API + // Generate basic type-safe DAO API for struct `model.User` following conventions + g.ApplyBasic( - // 根据 `user` 表生成结构 `User` - g.GenerateModel("users"), + // Generate struct `User` based on table `users` + g.GenerateModel("users"), - // 根据 `user` 表生成结构 `Employee` - g.GenerateModelAs("users", "Employee"), + // Generate struct `Employee` based on table `users` + g.GenerateModelAs("users", "Employee"), - // 根据 `user` 表和生成时选项生成结构 `User` - g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), - ) - g.ApplyBasic( - // 从当前数据库中生成所有表的结构 - g.GenerateAllTable()..., - ) +// Generate struct `User` based on table `users` and generating options +g.GenerateModel("users", gen.FieldIgnore("address"), gen.FieldType("id", "int64")), - // 生成代码 +// Generate struct `Customer` based on table `customer` and generating options +// customer table may have a tags column, it can be JSON type, gorm/gen tool can generate for your JSON data type +g.GenerateModel("customer", gen.FieldType("tags", "datatypes.JSON")), + + ) +g.ApplyBasic( +// Generate structs from all tables of current database +g.GenerateAllTable()..., +) + // Generate the code g.Execute() }