MCPcopy
hub / github.com/sourcegraph/checkup / dbConnect

Method dbConnect

storage/sql/sql.go:63–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63func (sql Storage) dbConnect() (*sqlx.DB, error) {
64 // Only one SQL backend can be present
65 if sql.SqliteDBFile != "" && sql.PostgreSQL != nil {
66 return nil, errors.New("several SQL backends are configured")
67 }
68
69 // SQLite3 configuration
70 if sql.SqliteDBFile != "" {
71 return sqlx.Connect("sqlite3", sql.SqliteDBFile)
72 }
73
74 // PostgreSQL configuration
75 if sql.PostgreSQL != nil {
76 var pgOptions string
77 if sql.PostgreSQL.DBName == "" {
78 return nil, errors.New("missing PostgreSQL database name")
79 }
80 if sql.PostgreSQL.User == "" {
81 return nil, errors.New("missing PostgreSQL username")
82 }
83 if sql.PostgreSQL.Host != "" {
84 pgOptions += " host=" + sql.PostgreSQL.Host
85 }
86 if sql.PostgreSQL.Port != 0 {
87 pgOptions += " port=" + strconv.Itoa(sql.PostgreSQL.Port)
88 }
89 pgOptions += " user=" + sql.PostgreSQL.User
90 if sql.PostgreSQL.Password != "" {
91 pgOptions += " password=" + sql.PostgreSQL.Password
92 }
93 pgOptions += " dbname=" + sql.PostgreSQL.DBName
94 if sql.PostgreSQL.SSLMode != "" {
95 pgOptions += " sslmode=" + sql.PostgreSQL.SSLMode
96 }
97 return sqlx.Connect("postgres", pgOptions)
98 }
99
100 // TODO: MySQL backend?
101
102 return nil, errors.New("no configured database backend")
103}
104
105// GetIndex returns the list of check results for the database.
106func (sql Storage) GetIndex() (map[string]int64, error) {

Callers 5

GetIndexMethod · 0.95
FetchMethod · 0.95
StoreMethod · 0.95
MaintainMethod · 0.95
initializeMethod · 0.95

Implementers 5

fakecheckup_test.go
Storagestorage/sql/sql.go
Storagestorage/s3/s3.go
Storagestorage/github/github.go
Storagestorage/fs/fs.go

Calls

no outgoing calls

Tested by

no test coverage detected