Yahoo奇摩 網頁搜尋

搜尋結果

  1. 2024年4月23日 · GEN 指南GEN: 更友好 & 更安全 GORM 代码生成。 概览 Idiomatic & Reusable API from Dynamic Raw SQL 100% Type-safe DAO API without interface{} Database To Struct follows GORM conventions GORM under the

  2. 2024年4月23日 · Create Hooks. GORM allows user defined hooks to be implemented for BeforeSave, BeforeCreate, AfterSave, AfterCreate. These hook method will be called when creating a record, refer Hooks for details on the lifecycle. func (u *User) BeforeCreate(tx *gorm.DB) (err error) {. u.UUID = uuid.New() if u.Role == "admin" {.

  3. 2024年4月23日 · GORM provides the Changed method which could be used in Before Update Hooks, it will return whether the field has changed or not. The Changed method only works with methods Update, Updates, and it only checks if the updating value from Update / Updates equals the model value. It will return true if it is changed and not omitted.

  4. 2024年4月23日 · Sharding. Sharding 是一个高性能的 Gorm 分表中间件。. 它基于 Conn 层做 SQL 拦截、AST 解析、分表路由、自增主键填充,带来的额外开销极小。. 对开发者友好、透明,使用上与普通 SQL、Gorm 查询无差别,只需要额外注意一下分表键条件。. 为您提供高性能的数据库访问 ...

  5. 2024年4月23日 · 自定义预加载 SQL. You are able to custom preloading SQL by passing in func(db *gorm.DB) *gorm.DB, for example: db.Preload("Orders", func(db *gorm.DB) *gorm.DB {. return db.Order("orders.amount DESC") }).Find(&users) // SELECT * FROM users; // SELECT * FROM orders WHERE user_id IN (1,2,3,4) order by orders.amount DESC;

  6. 2024年4月23日 · GORM 允许通过 index、uniqueIndex 标签创建索引,这些索引将在使用 GORM 进行AutoMigrate 或 Createtable 时创建 索引标签GORM 可以接受很多索引设置,例如class、type、where、comment、expression、sort、collate、option 下面的示例演示了如何使用它: type User struct {

  7. 2024年4月23日 · 你可以通过 db.CreateInBatches 方法来指定批量插入的批次大小. Upsert 和 Create With Associations 同样支持批量插入. 注意 使用 CreateBatchSize 选项初始化GORM实例后,此后进行创建& 关联操作时所有的 INSERT 行为都会遵循初始化时的配置。. CreateBatchSize: 1000, users = [5000]User{{Name ...