pgdriver_go

package module
v0.0.0-...-142cc3d Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2018 License: BSD-2-Clause Imports: 13 Imported by: 0

README

pgdriver-go

This is an open source driver for postgresql and written by pure golang.

Usage:

get connection:

pgUrl := "postgres://username:password@host-ip:port"
driver := &pgdriver_go.PGDriver{}
conn, err := driver.Open(pgUrl)

simple query:

sql := "select current_database(), current_schema(), current_user"
stmt, err := conn.Prepare(sql)
if err != nil {
    //...
}
rows, err := stmt.Query(nil)
//handl rows if err is nil...

prepare statement query:

sql := "select * from user where name=$1 and age=$2"
stmt, err := conn.Prepare(sql)
if err != nil {
    //...
}
rows, err := conn.Query([]driver.Value{"name", 25})
//handl rows if err is nil...

prepare statement (creat,update,delete):

sql := "update user set name=$1,age=$2 where id = $3"
stmt, err := conn.Prepare(sql)
if err != nil {
    //...
}
tx, err := conn.Begin()
result, err := stmt.Exec([]driver.Value{"name", 25, "id"})
if err != nil {
    tx.Rollback()
} else {
    tx.Commit()
}

Documentation

Index

Constants

View Source
const (
	KerberosV5
	PlaintText

	Md5
	SCM
	GSSAPI

	SSPI
)
View Source
const (
	ZeroByte = 0x00
)

Variables

View Source
var (
	UrlErr      = "Invalid url format, please use format postgres://user:pass@ip:port/db"
	ProtocolErr = "Protocol must be postgres or postgresql."
	AuthErr     = "Invalid password."
	CmdErr      = "Unsupported command."
	NoMoreData  = "Has no more data."
	ParamErr    = "Parameters are invalid."
	QueryErr    = "Error returns when query."
	ReadyErr    = "Connection is busy."
)
View Source
var PGDataType map[string]int32

Functions

This section is empty.

Types

type Messages

type Messages struct {
	Msgs map[uint8]*msgType
}

func (*Messages) New

func (msg *Messages) New()

type PGConn

type PGConn struct {
	DateStyle string
	TimeZone  string

	IntervalStyle string
	// contains filtered or unexported fields
}

func (*PGConn) Begin

func (conn *PGConn) Begin() (driver.Tx, error)

func (*PGConn) Close

func (conn *PGConn) Close() error

func (*PGConn) Prepare

func (conn *PGConn) Prepare(query string) (driver.Stmt, error)

func (*PGConn) Query

func (conn *PGConn) Query(query string, args []driver.Value) (driver.Rows, error)

type PGDriver

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

func (*PGDriver) Open

func (d *PGDriver) Open(name string) (driver.Conn, error)

type PGResult

type PGResult struct {
}

func (*PGResult) LastInsertId

func (r *PGResult) LastInsertId() (int64, error)

func (*PGResult) RowsAffected

func (r *PGResult) RowsAffected() (int64, error)

type PGRows

type PGRows struct {
	Data [][]driver.Value
	// contains filtered or unexported fields
}

func (*PGRows) Close

func (r *PGRows) Close() error

func (*PGRows) Columns

func (r *PGRows) Columns() []string

func (*PGRows) Next

func (r *PGRows) Next(dest []driver.Value) error

type PGStmt

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

func (*PGStmt) Close

func (stmt *PGStmt) Close() error

func (*PGStmt) Exec

func (stmt *PGStmt) Exec(args []driver.Value) (driver.Result, error)

func (*PGStmt) NumInput

func (stmt *PGStmt) NumInput() int

func (*PGStmt) Query

func (stmt *PGStmt) Query(args []driver.Value) (driver.Rows, error)

type PGTx

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

func (*PGTx) Commit

func (tx *PGTx) Commit() error

func (*PGTx) Rollback

func (tx *PGTx) Rollback() error

Jump to

Keyboard shortcuts

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