postgres

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 14 Imported by: 0

README

GORM PostgreSQL Driver

Quick Start

import (
  og "github.com/stitchcula/OpenGauss"
  "gorm.io/gorm"
)

// gitee.com/opengauss/openGauss-connector-go-pq
config := og.Config{
    Host:     "192.168.xx.xx",
    Port:     5432,
    Database: "db_tpcc",
    User:     "user_persistence",
    Password: "1234@abc",
    RuntimeParams: map[string]string{
    "search_path": "my_schema",
    },
}
db, err := gorm.Open(og.New(config), &gorm.Config{})

Checkout https://gorm.io for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(config Config) gorm.Dialector

func Open

func Open(dsn string) gorm.Dialector

Types

type Config

type Config struct {
	Host           string // host (e.g. localhost) or absolute path to unix domain socket directory (e.g. /private/tmp)
	Port           uint16
	Database       string
	User           string
	Password       string
	TLSConfig      *tls.Config // nil disables TLS
	ConnectTimeout time.Duration
	//DialFunc       pq.DialFunc   // e.g. net.Dialer.DialContext
	//LookupFunc     pq.LookupFunc // e.g. net.Resolver.LookupHost
	// BuildFrontend  BuildFrontendFunc
	RuntimeParams map[string]string // Run-time parameters to set on connection as session default values (e.g. search_path or application_name)
	GssAPIParams  map[string]string
	Fallbacks     []*pq.FallbackConfig

	TargetSessionAttrs string
	MinReadBufferSize  int64 // The minimum size of the internal read buffer. Default 8192.
	CpBufferSize       int64 // Defines the size of the copy buffer. Default 65535.

	//Logger   pq.Logger
	LogLevel pq.LogLevel

	// When using the V3 protocol the driver monitors changes in certain server configuration parameters
	// that should not be touched by end users.
	// The client_encoding setting is set by the driver and should not be altered.
	// If the driver detects a change it will abort the connection.
	// There is one legitimate exception to this behaviour though,
	// using the COPY command on a file residing on the server's filesystem.
	// The only means of specifying the encoding of this file is by altering the client_encoding setting.
	// The JDBC team considers this a failing of the COPY command and hopes to provide an alternate means of specifying
	// the encoding in the future, but for now there is this URL parameter.
	// Enable this only if you need to override the client encoding when doing a copy.
	AllowEncodingChanges string
}

type Dialector

type Dialector struct {

	//   # Example DSN
	//   user=jack password=secret host=pg.example.com port=5432 dbname=mydb sslmode=verify-ca
	//
	//   # Example URL
	//   postgres://jack:secret@pg.example.com:5432/mydb?sslmode=verify-ca
	DSN string

	*Config
}

func (Dialector) BindVarTo

func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{})

func (Dialector) DataTypeOf

func (dialector Dialector) DataTypeOf(field *schema.Field) string

func (Dialector) DefaultValueOf

func (dialector Dialector) DefaultValueOf(field *schema.Field) clause.Expression

func (Dialector) Explain

func (dialector Dialector) Explain(sql string, vars ...interface{}) string

func (Dialector) Initialize

func (dialector Dialector) Initialize(db *gorm.DB) (err error)

func (Dialector) Migrator

func (dialector Dialector) Migrator(db *gorm.DB) gorm.Migrator

func (Dialector) Name

func (dialector Dialector) Name() string

func (Dialector) QuoteTo

func (dialector Dialector) QuoteTo(writer clause.Writer, str string)

func (Dialector) RollbackTo

func (dialector Dialector) RollbackTo(tx *gorm.DB, name string) error

func (Dialector) SavePoint

func (dialector Dialector) SavePoint(tx *gorm.DB, name string) error

func (Dialector) Translate

func (dialector Dialector) Translate(err error) error

type Index

type Index struct {
	TableName  string `gorm:"column:table_name"`
	ColumnName string `gorm:"column:column_name"`
	IndexName  string `gorm:"column:index_name"`
	NonUnique  bool   `gorm:"column:non_unique"`
	Primary    bool   `gorm:"column:primary"`
}

Index table index info

type Migrator

type Migrator struct {
	migrator.Migrator
}

func (Migrator) AddColumn

func (m Migrator) AddColumn(value interface{}, field string) error

func (Migrator) AlterColumn

func (m Migrator) AlterColumn(value interface{}, field string) error

AlterColumn alter value's `field` column' type based on schema definition

func (Migrator) BuildIndexOptions

func (m Migrator) BuildIndexOptions(opts []schema.IndexOption, stmt *gorm.Statement) (results []interface{})

func (Migrator) ColumnTypes

func (m Migrator) ColumnTypes(value interface{}) (columnTypes []gorm.ColumnType, err error)

func (Migrator) CreateIndex

func (m Migrator) CreateIndex(value interface{}, name string) error

func (Migrator) CreateSequence

func (m Migrator) CreateSequence(tx *gorm.DB, stmt *gorm.Statement, field *schema.Field,
	serialDatabaseType string) (err error)

func (Migrator) CreateTable

func (m Migrator) CreateTable(values ...interface{}) (err error)

func (Migrator) CurrentDatabase

func (m Migrator) CurrentDatabase() (name string)

func (Migrator) CurrentSchema

func (m Migrator) CurrentSchema(stmt *gorm.Statement, table string) (interface{}, interface{})

func (Migrator) DeleteSequence

func (m Migrator) DeleteSequence(tx *gorm.DB, stmt *gorm.Statement, field *schema.Field,
	fileType clause.Expr) (err error)

func (Migrator) DropColumn

func (m Migrator) DropColumn(dst interface{}, field string) error

func (Migrator) DropIndex

func (m Migrator) DropIndex(value interface{}, name string) error

func (Migrator) DropTable

func (m Migrator) DropTable(values ...interface{}) error

func (Migrator) GetIndexes

func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error)

func (Migrator) GetRows

func (m Migrator) GetRows(currentSchema interface{}, table interface{}) (*sql.Rows, error)

func (Migrator) GetTables

func (m Migrator) GetTables() (tableList []string, err error)

func (Migrator) GetTypeAliases

func (m Migrator) GetTypeAliases(databaseTypeName string) []string

func (Migrator) HasColumn

func (m Migrator) HasColumn(value interface{}, field string) bool

func (Migrator) HasConstraint

func (m Migrator) HasConstraint(value interface{}, name string) bool

func (Migrator) HasIndex

func (m Migrator) HasIndex(value interface{}, name string) bool

func (Migrator) HasTable

func (m Migrator) HasTable(value interface{}) bool

func (Migrator) MigrateColumn

func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnType gorm.ColumnType) error

func (Migrator) RenameColumn

func (m Migrator) RenameColumn(dst interface{}, oldName, field string) error

func (Migrator) RenameIndex

func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error

func (Migrator) UpdateSequence

func (m Migrator) UpdateSequence(tx *gorm.DB, stmt *gorm.Statement, field *schema.Field,
	serialDatabaseType string) (err error)

Jump to

Keyboard shortcuts

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