sql

package module
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 12 Imported by: 2

README

GoZix SQL

License Documentation

Release Build Status Go Report Card Code Coverage

The bundle provide a SQL integration to GoZix application.

Installation

go get github.com/gozix/sql/v3

Dependencies

Configuration example

{
  "sql": {
    "default": {
      "nodes": [
        "postgres://app:password@127.0.0.1:5432/app?sslmode=disable"
      ],
      "driver": "postgres",
      "max_open_conns": 10,
      "max_idle_conns": 10,
      "conn_max_lifetime": "10m"
    }
  }
}

Documentation

You can find documentation on pkg.go.dev and read source code if needed.

Questions

If you have any questions, feel free to create an issue.

Documentation

Index

Constants

View Source
const BundleName = "sql"

BundleName is default definition name.

View Source
const DEFAULT = "default"

DEFAULT is default connection name.

Variables

View Source
var (
	// ErrUnknownConnection is error triggered when connection with provided name not founded.
	ErrUnknownConnection = errors.New("unknown connection")
)

Functions

This section is empty.

Types

type Bundle

type Bundle struct{}

Bundle implements the glue.Bundle interface.

func NewBundle

func NewBundle() *Bundle

NewBundle create bundle instance.

func (*Bundle) Build

func (b *Bundle) Build(builder di.Builder) error

Build implements the glue.Bundle interface.

func (*Bundle) DependsOn

func (b *Bundle) DependsOn() []string

func (*Bundle) Name

func (b *Bundle) Name() string

type Config

type Config struct {
	Nodes           []string                      `json:"nodes"`
	Driver          string                        `json:"driver"`
	MaxOpenConns    int                           `json:"max_open_conns"`
	MaxIdleConns    int                           `json:"max_idle_conns"`
	ConnMaxLifetime time.Duration                 `json:"conn_max_lifetime"`
	AfterOpen       func(name string, db *nap.DB) `json:"-"`
}

Config is registry configuration item.

type Configs

type Configs map[string]Config

Configs are registry configurations.

type Registry

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

Registry is database connection registry.

func NewRegistry

func NewRegistry(conf Configs) (*Registry, error)

NewRegistry is registry constructor.

func (*Registry) Close

func (r *Registry) Close() (err error)

Close is method for close connections.

func (*Registry) Connection

func (r *Registry) Connection() (*nap.DB, error)

Connection is default connection getter.

func (*Registry) ConnectionWithName

func (r *Registry) ConnectionWithName(name string) (_ *nap.DB, err error)

ConnectionWithName is connection getter by name.

func (*Registry) Driver

func (r *Registry) Driver() (string, error)

Driver is default connection driver name getter.

func (*Registry) DriverWithName

func (r *Registry) DriverWithName(name string) (string, error)

DriverWithName is driver name getter by name.

Jump to

Keyboard shortcuts

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