# 注入Gorm和XOrm

首先创建一个DBConfig 写入如下内容:

别忘了在main里面注册这个DBConfig

```
import (
   _ "github.com/go-sql-driver/mysql"
   "github.com/jinzhu/gorm"
   "log"
   "mygin/src/daos"
   "xorm.io/xorm"
)

type DBConfig struct {
}
func NewDBConfig() *DBConfig {
   return &DBConfig{}
}

func(this *DBConfig) GormDB() *gorm.DB{
   db, err := gorm.Open("mysql",
      "root:123123@tcp(localhost:3307)/test?charset=utf8mb4&parseTime=True&loc=Local")
   if err != nil {
      log.Fatal(err)
   }
   db.DB().SetMaxIdleConns(5)
   db.DB().SetMaxOpenConns(10)
   return db
}
func(this *DBConfig) XOrm() *daos.XOrmAdapter{
   engine, err := xorm.NewEngine("mysql", "root:123123@tcp(localhost:3307)/test?charset=utf8mb4&parseTime=True&loc=Local")
   if err != nil {
      log.Fatal(err)
   }
   engine.DB().SetMaxIdleConns(5)
   engine.DB().SetMaxOpenConns(10)
   return &daos.XOrmAdapter{Engine:engine}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://65480539.gitbook.io/goft/yi-lai-zhu-ru-he-orm/zhu-ru-gorm-he-xorm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
