pg

package module
v0.0.0-...-5e9c134 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2018 License: MIT Imports: 4 Imported by: 0

README

pg

Build Status Go Report Card GoDoc

https://github.com/jackc/pgx wrapper for internal usage

Install

$ go get github.com/zoer/pg

Usage

package main

import (
	"context"
	"log"

	"github.com/zoer/pg"
)

func main() {
	// creating a new DB pool
	pool, err := pg.NewPool(pg.PoolConfig{
		ConnConfig: ConnConfig{
			Host:     "127.0.0.1",
			Database: "test",
		},
		MaxConnections: 3,
	})
	if err != nil {
		log.Fatalf("unable connect to database: %v", err)
	}
	defer pool.Close()

	var i int
	if err = pool.QueryRow(context.TODO(), "SELECT $1", 123).Scan(&i); err != nil {
		log.Fatalf("unable to query: %v", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandTag

type CommandTag interface {
	RowsAffected() int64
}

CommandTag is a command's result interface

type ConnConfig

type ConnConfig struct {
	Host     string
	Port     uint16
	Database string
	User     string
	Password string
}

ConnConfig is a database connection config

type ConnPool

type ConnPool interface {
	io.Closer
	QueryRow(context.Context, string, ...interface{}) Row
	Query(context.Context, string, ...interface{}) (Rows, Error)
	Exec(context.Context, string, ...interface{}) (CommandTag, Error)

	CopyFrom([]string, []string, interface{}) error
}

ConnPool represents database pool interface

func NewPool

func NewPool(c PoolConfig) (ConnPool, error)

NewPool creates a new DB pool

type Error

type Error interface {
	Error() string
	Message() string
	Hint() string
	IsCode(string) bool
	NoRows() bool
}

Error is a database error interface

type PoolConfig

type PoolConfig struct {
	ConnConfig
	MaxConnections int
}

PoolConfig is a database connection config

type Row

type Row interface {
	Scan(...interface{}) Error
}

Row is a database row interface

type Rows

type Rows interface {
	Map(func(Row) error) Error
	Next() bool
	Scan(...interface{}) Error
	Close()
	Err() Error
}

Rows is a database rows interface

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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