You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
703 B
Go
34 lines
703 B
Go
6 months ago
|
// Package database provides utility functions for connecting to and
|
||
|
// interacting with various database backends.
|
||
|
//
|
||
|
// This package supports multiple database drivers including:
|
||
|
// - sqlite3
|
||
|
// - others coming soon...maybe
|
||
|
package database
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
|
||
|
"git.runcible.io/androiddrew/flux-feed/config"
|
||
|
"github.com/jmoiron/sqlx"
|
||
|
)
|
||
|
|
||
|
// NewSqlx configures a new sqlx.DB from application config
|
||
|
func NewSqlx(cfg config.Database) *sqlx.DB {
|
||
|
var dsn string
|
||
|
|
||
|
// TODO add additional database driver support
|
||
|
switch cfg.DatabaseDriver {
|
||
|
case "sqlite3":
|
||
|
dsn = cfg.DatabaseDSN
|
||
|
default:
|
||
|
log.Fatal("Must choose a database driver")
|
||
|
|
||
|
}
|
||
|
|
||
|
db := sqlx.MustConnect(cfg.DatabaseDriver, dsn)
|
||
|
|
||
|
return db
|
||
|
|
||
|
}
|