zdpgo_postgres

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2021 License: MIT Imports: 6 Imported by: 0

README

zdpgo_postgres

Golang操作PostgreSQL的基础组件

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CrudSql added in v1.0.2

type CrudSql interface {
	Add(sql string, args ...interface{}) int64                         // 添加数据
	Delete(table string, id int) bool                                  // 根据ID删除数据
	DeleteIds(table string, ids ...int) bool                           // 根据ID列表删除数据
	Update(sql string, args ...interface{}) bool                       // 根据ID修改数据
	Find(table string, columns []string, id int) pgx.Row               // 根据ID查询数据
	FindIds(table string, columns []string, ids []int) pgx.Rows        // 根据ID列表查询数据
	FindPages(table string, columns []string, page, size int) pgx.Rows // 根据分页查询数据
}

增删改查的SQL接口

type Postgres added in v1.0.2

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

PostgreSQL结构体

func New added in v1.0.2

func New(host string, port int, user, password, database, logPath string, debug bool) *Postgres

New 创建新的Postgres对象 @param host 主机地址 @param port 端口号 @param user 用户名 @param password 密码 @param database 数据库名称 @param logPath 日志存放路径 @param debug 是否为debug模式

func (*Postgres) Add added in v1.0.3

func (p *Postgres) Add(sql string, args ...interface{}) (affected int64)

添加数据

func (*Postgres) Delete added in v1.0.3

func (p *Postgres) Delete(table string, id int) (flag bool)

根据ID删除数据

func (*Postgres) DeleteIds added in v1.0.3

func (p *Postgres) DeleteIds(table string, ids ...int) (flag bool)

根据ID列表删除数据

func (*Postgres) Execute added in v1.0.2

func (p *Postgres) Execute(sql string, args ...interface{}) int64

Execute 执行增删改SQL语句

func (*Postgres) Find added in v1.0.2

func (p *Postgres) Find(table string, columns []string, id int) (row pgx.Row)

根据ID查询数据

func (*Postgres) FindIds added in v1.0.3

func (p *Postgres) FindIds(table string, columns []string, ids []int) (rows pgx.Rows)

根据ID列表查询数据

func (*Postgres) FindPages added in v1.0.3

func (p *Postgres) FindPages(table string, columns []string, page, size int) (rows pgx.Rows)

根据分页查询数据

func (*Postgres) Query added in v1.0.3

func (p *Postgres) Query(sql string, args ...interface{}) pgx.Row

Find 从数据库中查询单条数据

func (*Postgres) QueryMany added in v1.0.3

func (p *Postgres) QueryMany(sql string, args ...interface{}) (rows pgx.Rows, err error)

FindMany 从数据库中查询多条数据

func (*Postgres) SetDebug added in v1.0.2

func (p *Postgres) SetDebug(debug bool)

设置debug模式

func (*Postgres) SetLogPath added in v1.0.2

func (p *Postgres) SetLogPath(logPath string)

设置日志文件路径

func (*Postgres) Update added in v1.0.3

func (p *Postgres) Update(sql string, args ...interface{}) (flag bool)

根据ID修改数据

Directories

Path Synopsis
examples
z02_create_user command
z03_delete_user command
z04_update_user command
z05_find_user command
z06_crud_add command
z07_crud_update command
z08_crud_find command

Jump to

Keyboard shortcuts

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