MCPcopy
hub / github.com/harness/harness / prepareDatasourceForDriver

Function prepareDatasourceForDriver

store/database/store.go:95–117  ·  view source on GitHub ↗

prepareDatasourceForDriver ensures that required features are enabled on the datasource connection string based on the driver.

(driver string, datasource string)

Source from the content-addressed store, hash-verified

93// prepareDatasourceForDriver ensures that required features are enabled on the
94// datasource connection string based on the driver.
95func prepareDatasourceForDriver(driver string, datasource string) (string, error) {
96 switch driver {
97 case "sqlite3":
98 url, err := url.Parse(datasource)
99 if err != nil {
100 return "", fmt.Errorf("datasource is of invalid format for driver sqlite3")
101 }
102
103 // get original query and update it with required settings
104 query := url.Query()
105
106 // ensure foreign keys are always enabled (disabled by default)
107 // See https://github.com/mattn/go-sqlite3#connection-string
108 query.Set("_foreign_keys", "on")
109
110 // update url with updated query
111 url.RawQuery = query.Encode()
112
113 return url.String(), nil
114 default:
115 return datasource, nil
116 }
117}
118
119// helper function to ping the database with backoff to ensure
120// a connection can be established before we proceed with the

Callers 1

ConnectFunction · 0.85

Calls 5

ParseMethod · 0.65
SetMethod · 0.65
EncodeMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…