connection

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

README

go-connection

Release GoDoc Quality Test

An opinionated small PostgreSQL client library based on jmoiron/sqlx

about

A postgres client with support for enforcing transactions and allowing the user to utilize transactions with the same interface as when not in a transaction.

usage

ConnectFromEnv assumes environment variables:

DB_USER
DB_PASS
DB_HOST
DB_PORT
DB_DATABASE

to exist.

package main

import (
    "github.com/frederikhs/go-connection"
)

type City struct {
    Name string
    County string
}

func main()  {
    conn := connection.ConnectFromEnv()

    var cities []City
    err := conn.Select(&cities, "SELECT name, country FROM cities WHERE country = $1", "Denmark")
    if err != nil {
       panic(err)
    }
	
    ...
}
release

release a new version by creating a tag and pushing it

git tag -a v0.x.0 -m "v0.x.0"
git push origin v0.x.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransactionNotStarted     = errors.New("transaction not started")
	ErrTransactionAlreadyStarted = errors.New("transaction already started")
)
View Source
var TryDomain = "hiper.dk"

TryDomain is current just set to hiper.dk since I work at hiper

Functions

This section is empty.

Types

type Config

type Config struct {
	User     string
	Pass     string
	Host     string
	Port     string
	Database string
	Mode     SSLMode
}

func GetDatabaseEntryConnection added in v0.0.3

func GetDatabaseEntryConnection(hostQuery string, mode SSLMode) *Config

func NewConfig added in v0.0.3

func NewConfig(user, pass, host, port, database string, mode SSLMode) *Config

func NewConfigFromEnv added in v0.6.0

func NewConfigFromEnv() *Config

func (*Config) Connect

func (config *Config) Connect() *Conn

type Conn

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

func ConnectFromEnv

func ConnectFromEnv() *Conn

func (*Conn) Begin

func (conn *Conn) Begin() error

func (*Conn) Commit

func (conn *Conn) Commit() error

func (*Conn) Exec

func (conn *Conn) Exec(query string, args ...any) (sql.Result, error)

func (*Conn) NamedExec added in v0.0.3

func (conn *Conn) NamedExec(query string, arg any) (sql.Result, error)

func (*Conn) NamedQuery added in v0.0.3

func (conn *Conn) NamedQuery(query string, args any) (*sqlx.Rows, error)

func (*Conn) QueryRow

func (conn *Conn) QueryRow(query string, args ...any) *sql.Row

func (*Conn) Rebind

func (conn *Conn) Rebind(s string) string

func (*Conn) Rollback

func (conn *Conn) Rollback() error

func (*Conn) Select

func (conn *Conn) Select(dest interface{}, query string, args ...interface{}) error

func (*Conn) SelectContext

func (conn *Conn) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

type SSLMode added in v0.0.4

type SSLMode string
const (
	SSLModeDisable    SSLMode = "disable"
	SSLModeRequire    SSLMode = "require"
	SSLModeVerifyFull SSLMode = "verify-full"
	SSLModeVerifyCA   SSLMode = "verify-ca"
)

type Transactioner

type Transactioner interface {
	Begin() error
	Commit() error
	Rollback() error
}

Jump to

Keyboard shortcuts

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