mirror of
https://github.com/status-im/fathom.git
synced 2025-03-01 03:20:27 +00:00
stop exporting DB instance in datastore pkg. yay
This commit is contained in:
parent
a20e2b1227
commit
ac15507023
@ -1,7 +1,6 @@
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
_ "github.com/go-sql-driver/mysql" // mysql driver
|
||||
@ -11,21 +10,15 @@ import (
|
||||
"log"
|
||||
)
|
||||
|
||||
// DB holds the deprecated SQL connection pool. Try to use exported methods in this package instead.
|
||||
var DB *sql.DB
|
||||
|
||||
var dbx *sqlx.DB
|
||||
|
||||
// ErrNoResults is returned when a query yielded 0 results
|
||||
var ErrNoResults = errors.New("query returned 0 results")
|
||||
var ErrNoResults = errors.New("datastore: query returned 0 results")
|
||||
|
||||
// Init creates a database connection pool (using sqlx)
|
||||
func Init(driver string, host string, name string, user string, password string) *sqlx.DB {
|
||||
dbx = New(driver, getDSN(driver, host, name, user, password))
|
||||
|
||||
// store old sql.DB in exported var for backwards compat
|
||||
DB = dbx.DB
|
||||
|
||||
// run migrations
|
||||
runMigrations(driver)
|
||||
|
||||
@ -38,11 +31,6 @@ func New(driver string, dsn string) *sqlx.DB {
|
||||
return dbx
|
||||
}
|
||||
|
||||
// Get returns the underlying sqlx.DB instance. Use at your own risk.
|
||||
func Get() *sqlx.DB {
|
||||
return dbx
|
||||
}
|
||||
|
||||
func getDSN(driver string, host string, name string, user string, password string) string {
|
||||
var dsn = fmt.Sprintf("%s:%s@%s/%s", user, password, host, name)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user