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 ¶
- Constants
- Variables
- func Begin() (*pg.Tx, error)
- func BeginContext(ctx context.Context) (*pg.Tx, error)
- func Conn() *pg.Conn
- func Context() context.Context
- func CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res pg.Result, err error)
- func CopyTo(w io.Writer, query interface{}, params ...interface{}) (res pg.Result, err error)
- func Exec(query interface{}, params ...interface{}) (res pg.Result, err error)
- func ExecContext(c context.Context, query interface{}, params ...interface{}) (pg.Result, error)
- func ExecOne(query interface{}, params ...interface{}) (pg.Result, error)
- func ExecOneContext(ctx context.Context, query interface{}, params ...interface{}) (pg.Result, error)
- func Formatter() orm.QueryFormatter
- func Listen(ctx context.Context, channels ...string) *pg.Listener
- func Model(model ...interface{}) *orm.Query
- func ModelContext(c context.Context, model ...interface{}) *orm.Query
- func Param(param string) interface{}
- func Ping(ctx context.Context) error
- func PoolStats() *pg.PoolStats
- func Prepare(q string) (*pg.Stmt, error)
- func Query(model, query interface{}, params ...interface{}) (res pg.Result, err error)
- func QueryContext(c context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)
- func QueryOne(model, query interface{}, params ...interface{}) (pg.Result, error)
- func QueryOneContext(ctx context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)
- func RunInTransaction(ctx context.Context, fn func(*pg.Tx) error) error
- func WithContext(ctx context.Context) *pg.DB
- func WithParam(param string, value interface{}) *pg.DB
- func WithTimeout(d time.Duration) *pg.DB
- type Config
- type CreateCompositeOptions
- type CreateTableOptions
- type DebugHook
- type DropCompositeOptions
- type DropTableOptions
- type Error
- type OptionFunc
- type PostgreSQL
- func (pg *PostgreSQL) Begin() (*pg.Tx, error)
- func (pg *PostgreSQL) BeginContext(ctx context.Context) (*pg.Tx, error)
- func (pg *PostgreSQL) Conn() *pg.Conn
- func (pg *PostgreSQL) Context() context.Context
- func (pg *PostgreSQL) CopyFrom(r io.Reader, query interface{}, params ...interface{}) (res pg.Result, err error)
- func (pg *PostgreSQL) CopyTo(w io.Writer, query interface{}, params ...interface{}) (res pg.Result, err error)
- func (pg *PostgreSQL) Exec(query interface{}, params ...interface{}) (res pg.Result, err error)
- func (pg *PostgreSQL) ExecContext(c context.Context, query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) ExecOne(query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) ExecOneContext(ctx context.Context, query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) Formatter() orm.QueryFormatter
- func (pg *PostgreSQL) Listen(ctx context.Context, channels ...string) *pg.Listener
- func (pg *PostgreSQL) Model(model ...interface{}) *orm.Query
- func (pg *PostgreSQL) ModelContext(c context.Context, model ...interface{}) *orm.Query
- func (pg *PostgreSQL) Param(param string) interface{}
- func (pg *PostgreSQL) Ping(ctx context.Context) error
- func (pg *PostgreSQL) PoolStats() *pg.PoolStats
- func (pg *PostgreSQL) Prepare(q string) (*pg.Stmt, error)
- func (pg *PostgreSQL) Query(model, query interface{}, params ...interface{}) (res pg.Result, err error)
- func (pg *PostgreSQL) QueryContext(c context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) QueryOne(model, query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) QueryOneContext(ctx context.Context, model, query interface{}, params ...interface{}) (pg.Result, error)
- func (pg *PostgreSQL) RunInTransaction(ctx context.Context, fn func(*pg.Tx) error) error
- func (pg *PostgreSQL) Serve(ctx context.Context) error
- func (pg *PostgreSQL) Shutdown(ctx context.Context) error
- func (pg *PostgreSQL) WithContext(ctx context.Context) *pg.DB
- func (pg *PostgreSQL) WithParam(param string, value interface{}) *pg.DB
- func (pg *PostgreSQL) WithTimeout(d time.Duration) *pg.DB
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 BeginContext ¶
func ExecContext ¶
func ExecOneContext ¶
func Formatter ¶
func Formatter() orm.QueryFormatter
func QueryContext ¶
func QueryOneContext ¶
func WithContext ¶
func WithTimeout ¶
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 配置
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 ¶
type DropCompositeOptions ¶
type DropCompositeOptions = orm.DropCompositeOptions
type DropTableOptions ¶
type DropTableOptions = orm.DropTableOptions
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) 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) 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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.