Documentation ¶
Overview ¶
对go的postgresql数据库的操作的简单封装。 返回的结果集为map[string]any的切片,[]byte已经转为string。 仅支持查询功能,不支持事务。 仅支持yaml配置文件,不支持toml配置文件。 仅支持连接池,不支持连接共享。 仅支持简单查询,不支持复杂查询。
Index ¶
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Exec(sql string, args ...any) (sql.Result, error)
- func (c *Conn) Open() error
- func (c *Conn) Ping() error
- func (c *Conn) Query(sql string, args ...any) (result []map[string]any, err error)
- func (c *Conn) QueryRow(sql string, args ...any) (map[string]any, error)
- func (c *Conn) ReadFromYaml(confPath string) error
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 (*Conn) QueryRow ¶
同Query,仅返回第一行结果。 因为标准库的sql.QueryRow()中没有列名, 所以没有直接调用QueryRow(), 而是自己实现了一个QueryRow()
func (*Conn) ReadFromYaml ¶
ReadFromYaml 从yaml文件中读取配置信息 param confPath: yaml文件路径 注意: 初次使用,可以选择不创建yaml文件, 直接调用ReadFromYaml()方法,传入yaml文件的路径。 程序报错后,会在传入的路径下生成一个默认的yaml文件模版, 供用户参考,以及修改。
Click to show internal directories.
Click to hide internal directories.