------------------------------------------------------------------- Helpers -------------------------------------------------------------------
()
| 1173 | // ------------------------------------------------------------------- |
| 1174 | |
| 1175 | func (app *BaseApp) initDataDB() error { |
| 1176 | dbPath := filepath.Join(app.DataDir(), "data.db") |
| 1177 | |
| 1178 | concurrentDB, err := app.config.DBConnect(dbPath) |
| 1179 | if err != nil { |
| 1180 | return err |
| 1181 | } |
| 1182 | concurrentDB.DB().SetMaxOpenConns(app.config.DataMaxOpenConns) |
| 1183 | concurrentDB.DB().SetMaxIdleConns(app.config.DataMaxIdleConns) |
| 1184 | concurrentDB.DB().SetConnMaxIdleTime(3 * time.Minute) |
| 1185 | |
| 1186 | nonconcurrentDB, err := app.config.DBConnect(dbPath) |
| 1187 | if err != nil { |
| 1188 | return err |
| 1189 | } |
| 1190 | nonconcurrentDB.DB().SetMaxOpenConns(1) |
| 1191 | nonconcurrentDB.DB().SetMaxIdleConns(1) |
| 1192 | nonconcurrentDB.DB().SetConnMaxIdleTime(3 * time.Minute) |
| 1193 | |
| 1194 | if app.IsDev() { |
| 1195 | nonconcurrentDB.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) { |
| 1196 | color.HiBlack("[%.2fms] %v\n", float64(t.Milliseconds()), normalizeSQLLog(sql)) |
| 1197 | } |
| 1198 | nonconcurrentDB.ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) { |
| 1199 | color.HiBlack("[%.2fms] %v\n", float64(t.Milliseconds()), normalizeSQLLog(sql)) |
| 1200 | } |
| 1201 | concurrentDB.QueryLogFunc = nonconcurrentDB.QueryLogFunc |
| 1202 | concurrentDB.ExecLogFunc = nonconcurrentDB.ExecLogFunc |
| 1203 | } |
| 1204 | |
| 1205 | app.concurrentDB = concurrentDB |
| 1206 | app.nonconcurrentDB = nonconcurrentDB |
| 1207 | |
| 1208 | return nil |
| 1209 | } |
| 1210 | |
| 1211 | var sqlLogReplacements = []struct { |
| 1212 | pattern *regexp.Regexp |
no test coverage detected