pg

package module
v0.0.0-...-22208e0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

go-postgresql

介绍

GO连接postgresql的工具,采用yaml配置参数,包装返回结果为map。

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Overview

对go的postgresql数据库的操作的简单封装。 返回的结果集为map[string]any的切片,[]byte已经转为string。 仅支持查询功能,不支持事务。 仅支持yaml配置文件,不支持toml配置文件。 仅支持连接池,不支持连接共享。 仅支持简单查询,不支持复杂查询。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*sql.DB  `yaml:"db,omitempty"`
	DbConfig struct {
		Host   string `yaml:"host,omitempty"`
		Port   int    `yaml:"port,omitempty"`
		User   string `yaml:"user,omitempty"`
		Pass   string `yaml:"pass,omitempty"`
		DbName string `yaml:"dbname,omitempty"`
		SSL    string `yaml:"sslmode,omitempty"`
	} `yaml:"postgres,omitempty"`
}

func New

func New() *Conn

New 返回一个Conn结构体 等价于 &Conn{} TODO 后续考虑加入初始化配置

func (*Conn) Close

func (c *Conn) Close() error

可能会用到的Close 直接调用DB.Close(),未做处理。

func (*Conn) Exec

func (c *Conn) Exec(sql string, args ...any) (sql.Result, error)

直接调用的DB.Exec,未做处理。 TODO 考虑将返回改为仅error,考虑因素,是否有时会使用到sql.Result

func (*Conn) Open

func (c *Conn) Open() error

Open 连接数据库

func (*Conn) Ping

func (c *Conn) Ping() error

Ping 测试数据库连接是否正常 版主选择调用

func (*Conn) Query

func (c *Conn) Query(sql string, args ...any) (result []map[string]any, err error)

Query返回一个map[string]any的切片,[]byte已经转为string

func (*Conn) QueryRow

func (c *Conn) QueryRow(sql string, args ...any) (map[string]any, error)

同Query,仅返回第一行结果。 因为标准库的sql.QueryRow()中没有列名, 所以没有直接调用QueryRow(), 而是自己实现了一个QueryRow()

func (*Conn) ReadFromYaml

func (c *Conn) ReadFromYaml(confPath string) error

ReadFromYaml 从yaml文件中读取配置信息 param confPath: yaml文件路径 注意: 初次使用,可以选择不创建yaml文件, 直接调用ReadFromYaml()方法,传入yaml文件的路径。 程序报错后,会在传入的路径下生成一个默认的yaml文件模版, 供用户参考,以及修改。

Jump to

Keyboard shortcuts

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