diff --git a/pages/ar_SA/docs/create.md b/pages/ar_SA/docs/create.md index 7caca6cdf8d..e0866054a10 100644 --- a/pages/ar_SA/docs/create.md +++ b/pages/ar_SA/docs/create.md @@ -13,8 +13,8 @@ db. Omit("Name", "Age", "CreatedAt"). Create(&user) We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/az_AZ/docs/create.md b/pages/az_AZ/docs/create.md index 7dc71376762..d8252610158 100644 --- a/pages/az_AZ/docs/create.md +++ b/pages/az_AZ/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/de_DE/docs/create.md b/pages/de_DE/docs/create.md index 456a47b4477..120be56b114 100644 --- a/pages/de_DE/docs/create.md +++ b/pages/de_DE/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // Gibt die Anzahl der erstellten Einträge zurück We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/es_ES/docs/create.md b/pages/es_ES/docs/create.md index dd42e04fd97..eabb8802a0c 100644 --- a/pages/es_ES/docs/create.md +++ b/pages/es_ES/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // devuelve la cantidad de registros creados We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/fa_IR/docs/create.md b/pages/fa_IR/docs/create.md index 7dc71376762..d8252610158 100644 --- a/pages/fa_IR/docs/create.md +++ b/pages/fa_IR/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/fr_FR/docs/create.md b/pages/fr_FR/docs/create.md index 6baf7c81ba9..9f6e88c8ce4 100644 --- a/pages/fr_FR/docs/create.md +++ b/pages/fr_FR/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/hi_IN/docs/create.md b/pages/hi_IN/docs/create.md index 34ae7f01c74..70227ab399d 100644 --- a/pages/hi_IN/docs/create.md +++ b/pages/hi_IN/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // रिटर्न सम्मिलित रिकॉ `Create()` से हम ( create multiple records) कई रिकॉर्ड भी बना सकते हैं: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/id_ID/docs/advanced_query.md b/pages/id_ID/docs/advanced_query.md index 4250c6948f0..73b9d964afb 100644 --- a/pages/id_ID/docs/advanced_query.md +++ b/pages/id_ID/docs/advanced_query.md @@ -1,11 +1,11 @@ --- -title: Kueri Lanjutan +title: Query Lanjutan layout: page --- -## Bidang Pilih Pintar +## Query Lanjutan -In GORM, you can efficiently select specific fields using the [`Select`](query.html) method. This is particularly useful when dealing with large models but requiring only a subset of fields, especially in API responses. +Di Gorm, Anda bisa secara efektif untuk memilih field menggunakan metode [`Select`](query.html). Hal ini sangat berguna ketika Anda memiliki model data yang besar, tetapi hanya membutuhkan sebagian kecil dari field tersebut, terutama saat mengirimkan API response. ```go type User struct { diff --git a/pages/id_ID/docs/create.md b/pages/id_ID/docs/create.md index 7dc71376762..d8252610158 100644 --- a/pages/id_ID/docs/create.md +++ b/pages/id_ID/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/it_IT/docs/create.md b/pages/it_IT/docs/create.md index 7dc71376762..d8252610158 100644 --- a/pages/it_IT/docs/create.md +++ b/pages/it_IT/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/ja_JP/docs/create.md b/pages/ja_JP/docs/create.md index 11b0a16558f..1f0c02fcc47 100644 --- a/pages/ja_JP/docs/create.md +++ b/pages/ja_JP/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count `Create()` を使用して複数のレコードを作成することもできます: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/ko_KR/docs/create.md b/pages/ko_KR/docs/create.md index 920bd5c5409..e48705e6e76 100644 --- a/pages/ko_KR/docs/create.md +++ b/pages/ko_KR/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // 입력된 레코드의 개수를 반환합니다. We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/pl_PL/docs/create.md b/pages/pl_PL/docs/create.md index 7dc71376762..d8252610158 100644 --- a/pages/pl_PL/docs/create.md +++ b/pages/pl_PL/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // returns inserted records count We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/pt_BR/docs/create.md b/pages/pt_BR/docs/create.md index 1aed8349be7..b5f608bf76f 100644 --- a/pages/pt_BR/docs/create.md +++ b/pages/pt_BR/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // Retorna a contagem de registros criados We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/pt_BR/docs/delete.md b/pages/pt_BR/docs/delete.md index 7f1aa01b776..b53e1f51f0b 100644 --- a/pages/pt_BR/docs/delete.md +++ b/pages/pt_BR/docs/delete.md @@ -3,7 +3,7 @@ title: Excluir layout: page --- -## Delete a Record +## Apagar um registro When deleting a record, the deleted value needs to have primary key or it will trigger a [Batch Delete](#batch_delete), for example: diff --git a/pages/ru_RU/docs/create.md b/pages/ru_RU/docs/create.md index 5388197905f..fb817e807f5 100644 --- a/pages/ru_RU/docs/create.md +++ b/pages/ru_RU/docs/create.md @@ -18,14 +18,14 @@ result.RowsAffected // возвращает количество вставле Мы также можем создать несколько записей с помощью `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } -result := db.Create(users) // передайте фрагмент, чтобы вставить несколько строк +result := db.Create(users) // pass a slice to insert multiple row -result.Error // возвращает ошибку -result.RowsAffected // возвращает количество добавленных записей +result.Error // returns error +result.RowsAffected // returns inserted records count ``` {% note warn %} diff --git a/pages/tr_TR/docs/create.md b/pages/tr_TR/docs/create.md index 7104190672b..c8047573010 100644 --- a/pages/tr_TR/docs/create.md +++ b/pages/tr_TR/docs/create.md @@ -18,8 +18,8 @@ result.RowsAffected // oluşturulan kayıt sayısını döndür We can also create multiple records with `Create()`: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } result := db.Create(users) // pass a slice to insert multiple row diff --git a/pages/zh_CN/docs/create.md b/pages/zh_CN/docs/create.md index e45beacbff4..5f786535313 100644 --- a/pages/zh_CN/docs/create.md +++ b/pages/zh_CN/docs/create.md @@ -18,15 +18,17 @@ result.RowsAffected // 返回插入记录的条数 我们还可以使用 `Create()` 创建多项记录: ```go users := []*User{ - User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}, - User{Name: "Jackson", Age: 19, Birthday: time.Now()}, + {Name: "Jinzhu", Age: 18, Birthday: time.Now()}, + {Name: "Jackson", Age: 19, Birthday: time.Now()}, } -result := db.Create(users) // 传递切片以插入多行数据 +result := db.Create(users) // pass a slice to insert multiple row -result.Error // 返回 error -result.RowsAffected // 返回插入记录的条数 +result.Error // returns error +result.RowsAffected // returns inserted records count ``` + +{% note warn %} **NOTE** 你无法向 'create' 传递结构体,所以你应该传入数据的指针. {% endnote %} diff --git a/pages/zh_CN/docs/models.md b/pages/zh_CN/docs/models.md index 13b94d9e111..a15e8fe88a8 100644 --- a/pages/zh_CN/docs/models.md +++ b/pages/zh_CN/docs/models.md @@ -14,41 +14,41 @@ GORM 通过将 Go 结构体(Go structs) 映射到数据库表来简化数据 ```go type User struct { ID uint // Standard field for the primary key - Name string // A regular string field - Email *string // A pointer to a string, allowing for null values - Age uint8 // An unsigned 8-bit integer + Name string // 一个常规字符串字段 + Email *string // 一个指向字符串的指针, allowing for null values + Age uint8 // 一个未签名的8位整数 Birthday *time.Time // A pointer to time.Time, can be null MemberNumber sql.NullString // Uses sql.NullString to handle nullable strings ActivatedAt sql.NullTime // Uses sql.NullTime for nullable time fields - CreatedAt time.Time // Automatically managed by GORM for creation time - UpdatedAt time.Time // Automatically managed by GORM for update time + CreatedAt time.Time // 创建时间(由GORM自动管理) + UpdatedAt time.Time // 最后一次更新时间(由GORM自动管理) } ``` 在此模型中: -- Basic data types like `uint`, `string`, and `uint8` are used directly. -- Pointers to types like `*string` and `*time.Time` indicate nullable fields. -- `sql.NullString` and `sql.NullTime` from the `database/sql` package are used for nullable fields with more control. -- `CreatedAt` and `UpdatedAt` are special fields that GORM automatically populates with the current time when a record is created or updated. +- 具体数字类型如 `uint`、`string`和 `uint8` 直接使用。 +- 指向 `*string` 和 `*time.Time` 类型的指针表示可空字段。 +- 来自 `database/sql` 包的 `sql.NullString` 和 `sql.NullTime` 用于具有更多控制的可空字段。 +- `CreatedAt` 和 `UpdatedAt` 是特殊字段,当记录被创建或更新时,GORM 会自动向内填充当前时间。 -In addition to the fundamental features of model declaration in GORM, it's important to highlight the support for serialization through the serializer tag. This feature enhances the flexibility of how data is stored and retrieved from the database, especially for fields that require custom serialization logic, See [Serializer](serializer.html) for a detailed explanation +除了 GORM 中模型声明的基本特性外,强调下通过 serializer 标签支持序列化也很重要。 此功能增强了数据存储和检索的灵活性,特别是对于需要自定义序列化逻辑的字段。详细说明请参见 [Serializer](serializer.html)。 ### 约定 -1. **Primary Key**: GORM uses a field named `ID` as the default primary key for each model. +1. **主键**:GORM 使用一个名为`ID` 的字段作为每个模型的默认主键。 -2. **Table Names**: By default, GORM converts struct names to `snake_case` and pluralizes them for table names. For instance, a `User` struct becomes `users` in the database. +2. **表名**:默认情况下,GORM 将结构体名称转换为 `snake_case` 并为表名加上复数形式。 例如,一个 `User` 结构体在数据库中的表名变为 `users` 。 -3. **Column Names**: GORM automatically converts struct field names to `snake_case` for column names in the database. +3. **列名**:GORM 自动将结构体字段名称转换为 `snake_case` 作为数据库中的列名。 -4. **Timestamp Fields**: GORM uses fields named `CreatedAt` and `UpdatedAt` to automatically track the creation and update times of records. +4. **时间戳字段**:GORM使用字段 `CreatedAt` 和 `UpdatedAt` 来自动跟踪记录的创建和更新时间。 -Following these conventions can greatly reduce the amount of configuration or code you need to write. However, GORM is also flexible, allowing you to customize these settings if the default conventions don't fit your requirements. You can learn more about customizing these conventions in GORM's documentation on [conventions](conventions.html). +遵循这些约定可以大大减少您需要编写的配置或代码量。 但是,GORM也具有灵活性,允许您根据自己的需求自定义这些设置。 您可以在GORM的[约定](conventions.html)文档中了解更多关于自定义这些约定的信息。 ### `gorm.Model` -GORM provides a predefined struct named `gorm.Model`, which includes commonly used fields: +GORM提供了一个预定义的结构体,名为`gorm.Model`,其中包含常用字段: ```go // gorm.Model 的定义 @@ -60,13 +60,13 @@ type Model struct { } ``` -- **Embedding in Your Struct**: You can embed `gorm.Model` directly in your structs to include these fields automatically. This is useful for maintaining consistency across different models and leveraging GORM's built-in conventions, refer [Embedded Struct](#embedded_struct) +- **将其嵌入在您的结构体中**: 您可以直接在您的结构体中嵌入 `gorm.Model` ,以便自动包含这些字段。 这对于在不同模型之间保持一致性并利用GORM内置的约定非常有用,请参考[嵌入结构](#embedded_struct)。 -- **Fields Included**: - - `ID`: A unique identifier for each record (primary key). - - `CreatedAt`: Automatically set to the current time when a record is created. - - `UpdatedAt`: Automatically updated to the current time whenever a record is updated. - - `DeletedAt`: Used for soft deletes (marking records as deleted without actually removing them from the database). +- **包含的字段**: + - `ID` :每个记录的唯一标识符(主键)。 + - `CreatedAt` :在创建记录时自动设置为当前时间。 + - `UpdatedAt`:每当记录更新时,自动更新为当前时间。 + - `DeletedAt`:用于软删除(将记录标记为已删除,而实际上并未从数据库中删除)。 ## 高级选项