Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type IDatabase
- type ISQL
- type Instance
- func (i *Instance) CloseConnection() error
- func (i *Instance) GetConfig() *Config
- func (i *Instance) GetSQL() (*sql.DB, error)
- func (i *Instance) IsConnected() bool
- func (i *Instance) Ping() error
- func (i *Instance) SetConfig(cfg *Config) error
- func (i *Instance) SetConnected(v bool)
- func (i *Instance) SetPostgresConnection(con *sql.DB) error
- func (i *Instance) SetSQLiteConnection(con *sql.DB) error
- type Logger
Constants ¶
const ( // DBSQLite const string for sqlite across code base DBSQLite = "sqlite" // DBSQLite3 const string for sqlite3 across code base DBSQLite3 = "sqlite3" // DBPostgreSQL const string for PostgreSQL across code base DBPostgreSQL = "postgres" // DBInvalidDriver const string for invalid driver DBInvalidDriver = "invalid driver" )
Variables ¶
var ( // DB Global Database Connection DB = &Instance{} // MigrationDir which folder to look in for current migrations MigrationDir = filepath.Join("..", "..", "database", "migrations") // ErrNoDatabaseProvided error to display when no database is provided ErrNoDatabaseProvided = errors.New("no database provided") // ErrDatabaseSupportDisabled error to display when no database is provided ErrDatabaseSupportDisabled = errors.New("database support is disabled") // SupportedDrivers slice of supported database driver types SupportedDrivers = []string{DBSQLite, DBSQLite3, DBPostgreSQL} // ErrFailedToConnect for when a database fails to connect ErrFailedToConnect = errors.New("database failed to connect") // ErrDatabaseNotConnected for when a database is not connected ErrDatabaseNotConnected = errors.New("database is not connected") // DefaultSQLiteDatabase is the default sqlite3 database name to use DefaultSQLiteDatabase = "gocryptotrader.db" // ErrNilInstance for when a database is nil ErrNilInstance = errors.New("database instance is nil") // ErrNilConfig for when a config is nil ErrNilConfig = errors.New("received nil config") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Enabled bool `json:"enabled"` Verbose bool `json:"verbose"` Driver string `json:"driver"` drivers.ConnectionDetails `json:"connectionDetails"` }
Config holds all database configurable options including enable/disabled & DSN settings
type IDatabase ¶
IDatabase allows for the passing of a database struct without giving the receiver access to all functionality
type ISQL ¶
type ISQL interface { BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error) Exec(string, ...interface{}) (sql.Result, error) Query(string, ...interface{}) (*sql.Rows, error) QueryRow(string, ...interface{}) *sql.Row ExecContext(context.Context, string, ...interface{}) (sql.Result, error) QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) *sql.Row }
ISQL allows for the passing of a SQL connection without giving the receiver access to all functionality
type Instance ¶
Instance holds all information for a database instance
func (*Instance) CloseConnection ¶
CloseConnection safely disconnects the global database instance
func (*Instance) IsConnected ¶
IsConnected safely checks the SQL connection status
func (*Instance) SetConfig ¶
SetConfig safely sets the global database instance's config with some basic locks and checks
func (*Instance) SetConnected ¶
SetConnected safely sets the global database instance's connected status
func (*Instance) SetPostgresConnection ¶
SetPostgresConnection safely sets the global database instance's connection to use Postgres