orm

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

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 19 Imported by: 0

README

Title


P01

https://github.com/go-gorm/gorm/issues/4135 keep version of gorm.io/driver/postgres in v1.4.5, don't upgrade to 1.5.0

P02: migration

go install -tags 'postgres mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

go install github.com/mikefarah/yq/v4@latest
migrate create -ext sql -dir migrations -seq alter_key_invocations

echo "export DATABASE_URL=postgresql://hello:world@localhost:5433/simple_bank?sslmode=disable" > .env

. .env

migrate -path migrations -database "$DATABASE_URL" -verbose up

migrate -path migrations -database "$DATABASE_URL" -verbose down -all

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GormDBClose

func GormDBClose(gdb *gorm.DB) (err error)

func GormFlip

func GormFlip(tx *gorm.DB, pageSize, pageNo int) *gorm.DB

func GormMultiEquals

func GormMultiEquals[T comparable](tx *gorm.DB, field string, values []T) *gorm.DB

func GormMySQLConnect

func GormMySQLConnect(dsn string, debug bool) (db *gorm.DB, err error)

MySQL initialize

dsn format: {USERANME}:{PASSWORD}@tcp({IP})/{DATABASE}?charset=utf8mb4&parseTime=True&loc=Local

func GormMySQLIsNotFound

func GormMySQLIsNotFound(err error) bool

errors

func GormMySQLUniqueViolation

func GormMySQLUniqueViolation(err error) bool

func GormPgConnect

func GormPgConnect(dsn string, debugMode bool) (db *gorm.DB, err error)

dsn format: - postgres://{USERANME}:{PASSWORD}@tcp({IP})/{DATABASE}?sslmode=disable - "host=%s port=5432 user=%s dbname=%s password=%s sslmode=disable TimeZone=Asia/Shanghai"

func GormPgNotFound

func GormPgNotFound(err error) bool

func GormPgUniqueViolation

func GormPgUniqueViolation(err error) bool

!!! works as expected only version(gorm.io/driver/postgres) <= v1.4.5

and errors.Is(e, gorm.ErrDuplicatedKey) doesn't work as expected

func MigratePgDir

func MigratePgDir(dsn, migrations string) (err error)

func MigratePgFs

func MigratePgFs(dsn string, src embed.FS, subpath string) (err error)

//go:embed migrations/*.sql src embed.FS

MigratePgFs(dsn, src, "migrations")

Types

type Hashmap

type Hashmap[T any] map[string]T

dict

func (*Hashmap[T]) Scan

func (dict *Hashmap[T]) Scan(value any) (err error)

func (Hashmap[T]) Value

func (dict Hashmap[T]) Value() (driver.Value, error)

type PageResult

type PageResult[T any] struct {
	Total int64 `json:"total"`
	Items []T   `json:"items"`
}

result

func NewPageResult

func NewPageResult[T any]() *PageResult[T]

func (PageResult[T]) AsMap

func (result PageResult[T]) AsMap() map[string]any

type Vector

type Vector[T any] []T // T should marshalable

vector

func (*Vector[T]) Scan

func (vec *Vector[T]) Scan(value any) (err error)

func (Vector[T]) Value

func (vec Vector[T]) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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