gorm4gaussdb

package module
v0.0.0-...-d9d7a96 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

README

gorm4gaussdb

GORM 是一个强大的Go编程语言中的ORM库,具有简单易用、多数据库支持、自动迁移、事务支持和强大的查询功能等特点。

云数据库 GaussDB 是华为自主创新研发的分布式关系型数据库。该产品具备企业级复杂事务混合负载能力,同时支持分布式事务,同城跨AZ部署,数据0丢失,支持1000+的扩展能力,PB级海量存储。同时拥有云上高可用,高可靠,高安全,弹性伸缩,一键部署,快速备份恢复,监控告警等关键能力。

本项目的目的是让 GORM 支持华为云数据库 GaussDB。开源软件 for Huawei 之 GORM 操作华为云数据库 GaussDB 攻略【最终章】

Quick Start

import (
  gaussdb "github.com/okyer/gorm4gaussdb"
  "gorm.io/gorm"
)

dsn := "host=127.0.0.1 user=test password=123456 dbname=test port=8000 sslmode=disable TimeZone=Asia/Shanghai"
db, err := gorm.Open(gaussdb.Open(dsn), &gorm.Config{})
if err != nil {
    panic(err)
}
// TODO...

examples

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 {
	DriverName           string
	DSN                  string
	WithoutQuotingCheck  bool
	PreferSimpleProtocol bool
	WithoutReturning     bool
	Conn                 gorm.ConnPool
}

type Dialector

type Dialector struct {
	*Config
}

func (Dialector) Apply

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

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

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

type ErrMessage struct {
	Code     string
	Severity string
	Message  string
}

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