db

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 13 Imported by: 0

README

upper.io/db.v3 Module for Helium

Default modules

  • MySQL - to connection database.mysql
  • PG - to connection database.postgres

Example configuration

database:
  mysql:
    adapter: mysql
    hostname: 127.0.0.1:3306
    database: mysql
    username: root
    password:
    debug: true
    options:
      parseTime: true
  postgres:
    adapter: postgres
    hostname: 127.0.0.1:5432
    database: postgres
    username: postgres
    password: postgres
    debug: true
    options:
      sslmode: disable
  mssql:
    adapter: mssql
    hostname: 127.0.0.1:1433
    database: master
    username: test
    password: test
    debug: true
  mongo:
    adapter: mongo
    hostname: 127.0.0.1:27017
    database: master
    username: test
    password: test
    debug: true

Documentation

Index

Constants

View Source
const (
	// ErrEmptyConfig throws when db.ConnectionURL not passed into NewConnection
	ErrEmptyConfig = Error("empty config")

	// ErrEmptyAdapter throws when passed empty adapter into NewConnection
	ErrEmptyAdapter = Error("empty adapter")
	// ErrUnknownAdapter throws when passed unknown adapter into NewConnection
	ErrUnknownAdapter = Error("unknown adapter")

	// ErrConfigNotFound throws when config key is empty or not set
	ErrConfigNotFound = Error("configuration for key not found")
)

Variables

View Source
var (
	// MySQLModule default connection to mysql
	MySQLModule = module.Module{
		{Constructor: newMySQLConnection},
	}

	// PostgresModule default connection to postgres
	PostgresModule = module.Module{
		{Constructor: newPostgresConnection},
	}
)

Functions

func NewConnection

func NewConnection(opts ...ConnectionOption) (con db.Database, err error)

NewConnection creates new database connection by adapter and config

if cfg contains debug, than enable logging and replace default logger by zap.Logger

Types

type ConnectionOption

type ConnectionOption func(opts *ConnectionOptions)

ConnectionOption will be passed into NewConnection

func Adapter

func Adapter(adapter string) ConnectionOption

Adapter pass connection adapter into options

func Config

func Config(cfg db.ConnectionURL) ConnectionOption

Config pass connection url into options

func Debug

func Debug() ConnectionOption

Debug enable connection debug

func Logger

func Logger(log *zap.Logger) ConnectionOption

Logger pass connection logger into options

func PrepareConfig

func PrepareConfig(key string, v *viper.Viper, log *zap.Logger) ([]ConnectionOption, error)

PrepareConfig prepare options for connection

type ConnectionOptions

type ConnectionOptions struct {
	Logger  *zap.Logger
	URL     db.ConnectionURL
	Debug   bool
	Adapter string
}

ConnectionOptions will be passed into NewConnection

type ConnectionResult

type ConnectionResult struct {
	dig.Out

	MySQL MySQL `optional:"true" name:"default_mysql"`
	PG    PG    `optional:"true" name:"default_pg"`
}

ConnectionResult for default module

type Error

type Error string

Error is constant errors

func (Error) Error

func (e Error) Error() string

type MySQL

type MySQL interface {
	db.Database
	sqlbuilder.SQLBuilder
}

MySQL is wrapper over upper/db Database

type PG

type PG interface {
	db.Database
	sqlbuilder.SQLBuilder
}

PG is wrapper over upper/db Database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL