gopg

package
v1.0.0-beta.20 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/boxgo/box/pkg/client/gopg"
)

type (
	TestUserinfo struct {
		UserName string
		Age      int
	}
)

func main() {
	pg := gopg.StdConfig("default").Build()

	ts := &TestUserinfo{
		UserName: "box",
		Age:      18,
	}
	if err := pg.Model(ts).CreateTable(&gopg.CreateTableOptions{
		IfNotExists: true,
		Temp:        false,
	}); err != nil {
		panic(err)
	}

	if _, err := pg.Model(ts).Insert(); err != nil {
		panic(err)
	}

	fmt.Println(pg.Model(ts).DropTable(&gopg.DropTableOptions{}))
}
Output:

<nil>

Index

Examples

Constants

View Source
const (
	PrimaryKeyFlag = orm.PrimaryKeyFlag
	ForeignKeyFlag = orm.ForeignKeyFlag
	NotNullFlag    = orm.NotNullFlag
	UseZeroFlag    = orm.UseZeroFlag
	UniqueFlag     = orm.UniqueFlag
	ArrayFlag      = orm.ArrayFlag
)
View Source
const (
	InvalidRelation   = orm.InvalidRelation
	HasOneRelation    = orm.HasOneRelation
	BelongsToRelation = orm.BelongsToRelation
	HasManyRelation   = orm.HasManyRelation
	Many2ManyRelation = orm.Many2ManyRelation
)

Variables

View Source
var (
	// Discard is used with Query and QueryOne to discard rows.
	Discard = pg.Discard

	// ErrMultiRows is returned by QueryOne and ExecOne when query returned multiple rows but exactly one row is expected.
	ErrMultiRows = pg.ErrMultiRows

	// ErrNoRows is returned by QueryOne and ExecOne when query returned zero rows but at least one row is expected.
	ErrNoRows = pg.ErrNoRows

	// ErrTxDone is returned by any operation that is performed on a transaction that has already been committed or rolled back.
	ErrTxDone = pg.ErrTxDone
)
View Source
var (
	// Default instance
	Default = StdConfig("default").Build()
)

Functions

func Begin

func Begin() (*pg.Tx, error)

func BeginContext

func BeginContext(ctx context.Context) (*pg.Tx, error)

func Conn

func Conn() *pg.Conn

func Context

func Context() context.Context

func CopyFrom

func CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res pg.Result, err error)

func CopyTo

func CopyTo(w io.Writer, query interface{}, params ...interface{}) (res pg.Result, err error)

func Exec

func Exec(query interface{}, params ...interface{}) (res pg.Result, err error)

func ExecContext

func ExecContext(c context.Context, query interface{}, params ...interface{}) (pg.Result, error)

func ExecOne

func ExecOne(query interface{}, params ...interface{}) (pg.Result, error)

func ExecOneContext

func ExecOneContext(ctx context.Context, query interface{}, params ...interface{}) (pg.Result, error)

func Formatter

func Formatter() orm.QueryFormatter

func Listen

func Listen(ctx context.Context, channels ...string) *pg.Listener

func Model

func Model(model ...interface{}) *orm.Query

func ModelContext

func ModelContext(c context.Context, model ...interface{}) *orm.Query

func Param

func Param(param string) interface{}

func Ping

func Ping(ctx context.Context) error

func PoolStats

func PoolStats() *pg.PoolStats

func Prepare

func Prepare(q string) (*pg.Stmt, error)

func Query

func Query(model, query interface{}, params ...interface{}) (res pg.Result, err error)

func QueryContext

func QueryContext(c context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)

func QueryOne

func QueryOne(model, query interface{}, params ...interface{}) (pg.Result, error)

func QueryOneContext

func QueryOneContext(ctx context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)

func RunInTransaction

func RunInTransaction(ctx context.Context, fn func(*pg.Tx) error) error

func WithContext

func WithContext(ctx context.Context) *pg.DB

func WithParam

func WithParam(param string, value interface{}) *pg.DB

func WithTimeout

func WithTimeout(d time.Duration) *pg.DB

Types

type Config

type Config struct {
	Debug bool   `config:"debug" desc:"print all queries (even those without an error)"`
	URI   string `config:"uri" desc:"pg connection url. example: postgres://user:pass@localhost:5432/db_name?k=v"`
	// contains filtered or unexported fields
}

Config 配置

func DefaultConfig

func DefaultConfig(key string) *Config

DefaultConfig 默认配置

func StdConfig

func StdConfig(key string, optionFunc ...OptionFunc) *Config

StdConfig 标准配置

func (*Config) Build

func (c *Config) Build() *PostgreSQL

Build 构建实例

func (*Config) Path

func (c *Config) Path() string

Path 实例配置目录

type CreateCompositeOptions

type CreateCompositeOptions = orm.CreateCompositeOptions

type CreateTableOptions

type CreateTableOptions = orm.CreateTableOptions

type DebugHook

type DebugHook struct {
	// Verbose causes hook to print all queries (even those without an error).
	Verbose bool
}

DebugHook is a query hook that logs an error with a query if there are any. It can be installed with:

db.AddQueryHook(pgext.DebugHook{})

Copy from https://github.com/go-pg/pg/tree/v10/extra/pgdebug

func (DebugHook) AfterQuery

func (h DebugHook) AfterQuery(ctx context.Context, evt *pg.QueryEvent) error

func (DebugHook) BeforeQuery

func (h DebugHook) BeforeQuery(ctx context.Context, evt *pg.QueryEvent) (context.Context, error)

type DropCompositeOptions

type DropCompositeOptions = orm.DropCompositeOptions

type DropTableOptions

type DropTableOptions = orm.DropTableOptions

type Error

type Error = pg.Error

type OptionFunc

type OptionFunc func(*Config)

OptionFunc 选项信息

type PostgreSQL

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

func (*PostgreSQL) Begin

func (pg *PostgreSQL) Begin() (*pg.Tx, error)

func (*PostgreSQL) BeginContext

func (pg *PostgreSQL) BeginContext(ctx context.Context) (*pg.Tx, error)

func (*PostgreSQL) Conn

func (pg *PostgreSQL) Conn() *pg.Conn

func (*PostgreSQL) Context

func (pg *PostgreSQL) Context() context.Context

func (*PostgreSQL) CopyFrom

func (pg *PostgreSQL) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res pg.Result, err error)

func (*PostgreSQL) CopyTo

func (pg *PostgreSQL) CopyTo(w io.Writer, query interface{}, params ...interface{}) (res pg.Result, err error)

func (*PostgreSQL) Exec

func (pg *PostgreSQL) Exec(query interface{}, params ...interface{}) (res pg.Result, err error)

func (*PostgreSQL) ExecContext

func (pg *PostgreSQL) ExecContext(c context.Context, query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) ExecOne

func (pg *PostgreSQL) ExecOne(query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) ExecOneContext

func (pg *PostgreSQL) ExecOneContext(ctx context.Context, query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) Formatter

func (pg *PostgreSQL) Formatter() orm.QueryFormatter

func (*PostgreSQL) Listen

func (pg *PostgreSQL) Listen(ctx context.Context, channels ...string) *pg.Listener

func (*PostgreSQL) Model

func (pg *PostgreSQL) Model(model ...interface{}) *orm.Query

func (*PostgreSQL) ModelContext

func (pg *PostgreSQL) ModelContext(c context.Context, model ...interface{}) *orm.Query

func (*PostgreSQL) Param

func (pg *PostgreSQL) Param(param string) interface{}

func (*PostgreSQL) Ping

func (pg *PostgreSQL) Ping(ctx context.Context) error

func (*PostgreSQL) PoolStats

func (pg *PostgreSQL) PoolStats() *pg.PoolStats

func (*PostgreSQL) Prepare

func (pg *PostgreSQL) Prepare(q string) (*pg.Stmt, error)

func (*PostgreSQL) Query

func (pg *PostgreSQL) Query(model, query interface{}, params ...interface{}) (res pg.Result, err error)

func (*PostgreSQL) QueryContext

func (pg *PostgreSQL) QueryContext(c context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) QueryOne

func (pg *PostgreSQL) QueryOne(model, query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) QueryOneContext

func (pg *PostgreSQL) QueryOneContext(ctx context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)

func (*PostgreSQL) RunInTransaction

func (pg *PostgreSQL) RunInTransaction(ctx context.Context, fn func(*pg.Tx) error) error

func (*PostgreSQL) Serve

func (pg *PostgreSQL) Serve(ctx context.Context) error

func (*PostgreSQL) Shutdown

func (pg *PostgreSQL) Shutdown(ctx context.Context) error

func (*PostgreSQL) WithContext

func (pg *PostgreSQL) WithContext(ctx context.Context) *pg.DB

func (*PostgreSQL) WithParam

func (pg *PostgreSQL) WithParam(param string, value interface{}) *pg.DB

func (*PostgreSQL) WithTimeout

func (pg *PostgreSQL) WithTimeout(d time.Duration) *pg.DB

Jump to

Keyboard shortcuts

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