forked from stellar/go
/
init_db.go
37 lines (29 loc) · 849 Bytes
/
init_db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package horizon
import (
"github.com/stellar/go/services/horizon/internal/db2/core"
"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/log"
"github.com/stellar/go/support/db"
)
func initHorizonDb(app *App) {
session, err := db.Open("postgres", app.config.DatabaseURL)
if err != nil {
log.Panic(err)
}
session.DB.SetMaxIdleConns(4)
session.DB.SetMaxOpenConns(12)
app.historyQ = &history.Q{session}
}
func initCoreDb(app *App) {
session, err := db.Open("postgres", app.config.StellarCoreDatabaseURL)
if err != nil {
log.Panic(err)
}
session.DB.SetMaxIdleConns(4)
session.DB.SetMaxOpenConns(12)
app.coreQ = &core.Q{session}
}
func init() {
appInit.Add("horizon-db", initHorizonDb, "app-context", "log")
appInit.Add("core-db", initCoreDb, "app-context", "log")
}