db

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigConnection

func ConfigConnection(
	db *sql.DB,
	connMaxLifetime time.Duration,
	maxOpenConnections int,
	maxIdleConnections int,
)

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(app inter.App, connection inter.Connection) *Database

func (Database) Connection

func (d Database) Connection() inter.Connection

func (Database) Exec

func (d Database) Exec(sql string, args ...interface{}) sql.Result

Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (Database) ExecE

func (d Database) ExecE(sql string, args ...interface{}) (sql.Result, error)

ExecE executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (Database) Query

func (d Database) Query(sql string, args ...interface{}) support.Collection

Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func (Database) QueryE

func (d Database) QueryE(sql string, args ...interface{}) (support.Collection, error)

QueryE executes a query that returns rows or an error, typically a SELECT. The args are for any placeholder parameters in the query.

type MySQL

type MySQL struct {
	Host       string
	Port       int
	Database   string
	Username   string
	Password   string
	Parameters map[string]string

	// When the open connection limit is reached, and all connections are in-use,
	// any new database tasks that your application needs to execute will be forced
	// to wait until a connection becomes free and marked as idle. To mitigate this
	// you can set a fixed, fast, timeout when making database calls.
	// Default 10 seconds
	QueryTimeout time.Duration

	// Set the maximum lifetime of a connection to 1 hour. Setting it to 0 means
	// that there is no maximum lifetime and the connection is reused forever.
	// Default 5 minutes
	ConnMaxLifetime time.Duration

	// Set the maximum number of concurrently open connections (in-use + idle)
	// Setting this to less than 0 will mean there is no maximum limit.
	// Default 25
	MaxOpenConnections int

	// Set the maximum number of concurrently idle connections. Setting this
	// to less than 0 will mean that no idle connections are retained.
	// Default MaxOpenConnections
	MaxIdleConnections int
	// contains filtered or unexported fields
}

MySQL 4.1+ see https://github.com/go-sql-driver/mysql/

func (MySQL) NetworkAddress

func (m MySQL) NetworkAddress() string

func (*MySQL) Open

func (m *MySQL) Open() error

func (MySQL) Pool

func (m MySQL) Pool() *sql.DB

func (MySQL) Timeout

func (m MySQL) Timeout() time.Duration

type PostgreSQL

type PostgreSQL struct {
	// Host (e.g. localhost) or absolute path to unix domain socket directory (e.g. /private/tmp)
	Host     string
	Port     int
	Database string
	Username string
	Password string

	// nil disables TLS
	TLSConfig      *tls.Config
	ConnectTimeout time.Duration

	// e.g. net.Dialer.DialContext
	DialFunc pgconn.DialFunc

	// e.g. net.Resolver.LookupHost
	LookupFunc    pgconn.LookupFunc
	BuildFrontend pgconn.BuildFrontendFunc

	// Run-time parameters to set on connection as session default values (e.g. search_path or application_name)
	RuntimeParams map[string]string

	Fallbacks []*pgconn.FallbackConfig

	// ValidateConnect is called during a connection attempt after a successful authentication with the PostgreSQL server.
	// It can be used to validate that the server is acceptable. If this returns an error the connection is closed and the next
	// fallback config is tried. This allows implementing high availability behavior such as libpq does with target_session_attrs.
	ValidateConnect pgconn.ValidateConnectFunc

	// AfterConnect is called after ValidateConnect. It can be used to set up the connection (e.g. Set session variables
	// or prepare statements). If this returns an error the connection attempt fails.
	AfterConnect pgconn.AfterConnectFunc

	// OnNotice is a callback function called when a notice response is received.
	OnNotice pgconn.NoticeHandler

	// OnNotification is a callback function called when a notification from the LISTEN/NOTIFY system is received.
	OnNotification pgconn.NotificationHandler

	// When the open connection limit is reached, and all connections are in-use,
	// any new database tasks that your application needs to execute will be forced
	// to wait until a connection becomes free and marked as idle. To mitigate this
	// you can set a fixed, fast, timeout when making database calls.
	// Default 10 seconds
	QueryTimeout time.Duration

	// Set the maximum lifetime of a connection to 1 hour. Setting it to 0 means
	// that there is no maximum lifetime and the connection is reused forever.
	// Default 5 minutes
	ConnMaxLifetime time.Duration

	// Set the maximum number of concurrently open connections (in-use + idle)
	// Setting this to less than 0 will mean there is no maximum limit.
	// Default 25
	MaxOpenConnections int

	// Set the maximum number of concurrently idle connections. Setting this
	// to less than 0 will mean that no idle connections are retained.
	// Default MaxOpenConnections
	MaxIdleConnections int
	// contains filtered or unexported fields
}

func (*PostgreSQL) Open

func (m *PostgreSQL) Open() error

func (PostgreSQL) Pool

func (m PostgreSQL) Pool() *sql.DB

func (PostgreSQL) Timeout

func (m PostgreSQL) Timeout() time.Duration

Jump to

Keyboard shortcuts

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