postgres

package module
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MIT Imports: 15 Imported by: 9,763

README

GORM PostgreSQL Driver

Quick Start

import (
  "gorm.io/driver/postgres"
  "gorm.io/gorm"
)

// https://github.com/jackc/pgx
dsn := "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})

Configuration

import (
  "gorm.io/driver/postgres"
  "gorm.io/gorm"
)

db, err := gorm.Open(postgres.New(postgres.Config{
  DSN: "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable TimeZone=Asia/Shanghai", // data source name, refer https://github.com/jackc/pgx
  PreferSimpleProtocol: true, // disables implicit prepared statement usage. By default pgx automatically uses the extended protocol
}), &gorm.Config{})

Checkout https://gorm.io for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v0.2.5

func New(config Config) gorm.Dialector

func Open

func Open(dsn string) gorm.Dialector

Types

type Config added in v0.2.5

type Config struct {
	DriverName           string
	DSN                  string
	WithoutQuotingCheck  bool
	PreferSimpleProtocol bool
	WithoutReturning     bool
	Conn                 gorm.ConnPool
}

type Dialector

type Dialector struct {
	*Config
}

func (Dialector) Apply added in v1.5.5

func (dialector Dialector) Apply(config *gorm.Config) error

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 added in v0.2.2

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 added in v0.2.1

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

func (Dialector) SavePoint added in v0.2.1

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

func (Dialector) Translate added in v1.5.0

func (dialector Dialector) Translate(err error) error

Translate it will translate the error to native gorm errors. Since currently gorm supporting both pgx and pg drivers, only checking for pgx PgError types is not enough for translating errors, so we have additional error json marshal fallback.

type ErrMessage added in v1.5.1

type ErrMessage struct {
	Code     string
	Severity string
	Message  string
}

type Index added in v1.3.8

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 added in v1.0.6

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

func (Migrator) AlterColumn added in v1.3.1

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 added in v1.0.5

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 added in v1.3.5

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

func (Migrator) CreateTable added in v1.0.6

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

func (Migrator) CurrentDatabase

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

func (Migrator) CurrentSchema added in v1.0.6

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

func (Migrator) DeleteSequence added in v1.3.5

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

func (Migrator) DropColumn added in v1.4.5

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 added in v1.3.8

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

func (Migrator) GetRows added in v1.3.2

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

func (Migrator) GetTables added in v1.2.2

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

func (Migrator) GetTypeAliases added in v1.4.0

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

func (Migrator) HasColumn

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

func (Migrator) HasConstraint added in v0.2.3

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 added in v1.0.6

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

func (Migrator) RenameColumn added in v1.4.5

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 added in v1.3.5

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