postgres

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package postgres 实现了postgres的数据库方言Dialect,支持postgres 8.0+ 对应数据库

Index

Constants

View Source
const WriteModeCopyIn = "copyIn"

WriteModeCopyIn copy in写入方式

Variables

This section is empty.

Functions

func NewSource

func NewSource(bs *database.BaseSource) (s database.Source, err error)

NewSource 生成postgres数据源,在配置文件错误时会报错

func Quoted

func Quoted(s string) string

Quoted postgres引用函数

Types

type Config

type Config struct {
	URL      string `json:"url"`      //数据库url,包含数据库地址,数据库其他参数
	Username string `json:"username"` //用户名
	Password string `json:"password"` //密码
}

Config postgres配置

func NewConfig

func NewConfig(conf *config.JSON) (c *Config, err error)

NewConfig 创建postgres配置,如果格式不符合要求,就会报错

func (*Config) FormatDSN

func (c *Config) FormatDSN() (dsn string, err error)

FormatDSN 生成数据源连接信息,url有错会报错

type CopyInParam

type CopyInParam struct {
	*database.BaseParam
}

CopyInParam copy in 参数

func NewCopyInParam

func NewCopyInParam(t database.Table, txOpts *sql.TxOptions) *CopyInParam

NewCopyInParam 通过表table和事务参数txOps插入参数

func (*CopyInParam) Agrs

func (ci *CopyInParam) Agrs(records []element.Record) (valuers []interface{}, err error)

Agrs 通过多条记录 records生成批量copy in参数

func (*CopyInParam) Query

func (ci *CopyInParam) Query(_ []element.Record) (query string, err error)

Query 批量copy in插入sql语句

type Dialect

type Dialect struct{}

Dialect postgres数据库方言

func (Dialect) Name

func (d Dialect) Name() string

Name 数据库方言的注册名

func (Dialect) Source

func (d Dialect) Source(bs *database.BaseSource) (database.Source, error)

Source 生成postgres数据源

type Field

type Field struct {
	*database.BaseField
}

Field 字段

func NewField

func NewField(bf *database.BaseField) *Field

NewField 通过基本列属性生成字段

func (*Field) BindVar

func (f *Field) BindVar(i int) string

BindVar SQL占位符,用于SQL语句

func (*Field) Quoted

func (f *Field) Quoted() string

Quoted 引用,用于SQL语句

func (*Field) Scanner

func (f *Field) Scanner() database.Scanner

Scanner 扫描器,用于读取数据

func (*Field) Select

func (f *Field) Select() string

Select 查询时字段,用于SQL查询语句

func (*Field) Type

func (f *Field) Type() database.FieldType

Type 字段类型

func (*Field) Valuer

func (f *Field) Valuer(c element.Column) database.Valuer

Valuer 赋值器,采用GoValuer处理数据

type FieldType

type FieldType struct {
	*database.BaseFieldType
	// contains filtered or unexported fields
}

FieldType 字段类型

func NewFieldType

func NewFieldType(typ database.ColumnType) *FieldType

NewFieldType 创建新的字段类型

func (*FieldType) GoType

func (f *FieldType) GoType() database.GoType

GoType 返回处理数值时的Golang类型

func (*FieldType) IsSupportted

func (f *FieldType) IsSupportted() bool

IsSupportted 是否支持解析

type Scanner

type Scanner struct {
	database.BaseScanner
	// contains filtered or unexported fields
}

Scanner 扫描器

func NewScanner

func NewScanner(f *Field) *Scanner

NewScanner 根据列类型生成扫描器

func (*Scanner) Scan

func (s *Scanner) Scan(src interface{}) (err error)

Scan 根据列类型读取数据

type Source

type Source struct {
	*database.BaseSource //基础数据源
	// contains filtered or unexported fields
}

Source postgres数据源

func (*Source) ConnectName

func (s *Source) ConnectName() string

ConnectName github.com/Breeze0806/go/database/pqto的数据源连接信息

func (*Source) DriverName

func (s *Source) DriverName() string

DriverName github.com/Breeze0806/go/database/pqto的驱动名

func (*Source) Key

func (s *Source) Key() string

Key 数据源的关键字,用于DBWrapper的复用

func (*Source) Table

func (s *Source) Table(b *database.BaseTable) database.Table

Table 生成mysql的表

type Table

type Table struct {
	*database.BaseTable
}

Table postgres表

func NewTable

func NewTable(b *database.BaseTable) *Table

NewTable 创建postgres表,注意此时BaseTable中的schema参数为架构名,instance为数据库名,而name是表明

func (*Table) AddField

func (t *Table) AddField(baseField *database.BaseField)

AddField 新增列

func (*Table) ExecParam

func (t *Table) ExecParam(mode string, txOpts *sql.TxOptions) (database.Parameter, bool)

ExecParam 获取执行参数,其中copy in的参数方式以及被注册

func (*Table) Quoted

func (t *Table) Quoted() string

Quoted 引用全名

func (*Table) ShouldOneByOne

func (t *Table) ShouldOneByOne(err error) bool

ShouldOneByOne 单个重试

func (*Table) ShouldRetry

func (t *Table) ShouldRetry(err error) bool

ShouldRetry 重试

func (*Table) String

func (t *Table) String() string

Jump to

Keyboard shortcuts

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