vorm

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostgresDriver = "postgres"
	OracleDriver   = "oci8"
	MySQLDriver    = "mysql"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Foreign

type Foreign uint

Represents a database agnostic foreign key

func (*Foreign) Primary

func (x *Foreign) Primary() Primary

func (*Foreign) Scan

func (x *Foreign) Scan(src interface{}) error

func (*Foreign) Uint

func (x *Foreign) Uint() uint

func (*Foreign) Value

func (x *Foreign) Value() (driver.Value, error)

type JsonStringSlice

type JsonStringSlice []string

Represents a string list stored in the DB in JSON format.

func (*JsonStringSlice) Scan

func (l *JsonStringSlice) Scan(src interface{}) error

func (*JsonStringSlice) Value

func (l *JsonStringSlice) Value() (val driver.Value, err error)

type JsonbMap

type JsonbMap map[string]interface{}

Automatically converts JSON type from DB into a map[string]interface{}

func (*JsonbMap) Scan

func (p *JsonbMap) Scan(src interface{}) error

func (*JsonbMap) Truncate

func (p *JsonbMap) Truncate()

Truncate the map if it exceeds the byte size of the target DB

func (JsonbMap) Value

func (p JsonbMap) Value() (val driver.Value, err error)

type Model

type Model struct {
	*gorm.DB
}
var DB *Model

func InitDB

func InitDB(dataSourceName string) (*Model, error)

Connects to the DB based on the driver set in the env variable "DB_DRIVER" Currently supported values for DB_DRIVER = "postgres" for postgres, "oci8" for oracle

func InitMySQLDB

func InitMySQLDB(dataSourceName string) (*Model, error)

func InitOracleDB

func InitOracleDB(dataSourceName string) (*Model, error)

func InitPostgresDB

func InitPostgresDB(dataSourceName string) (*Model, error)

type ORM

type ORM struct {
	ID        Primary `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
}

Mimicks gorm.Model except ID is of type Primary

type ORMJson

type ORMJson struct {
	json.RawMessage
}

Use in migrations in case the DB entry is to be made in JSON format Can use JsonbMap or JsonStringSlice to automatically unmarshal from db into the desired data type in the actual code Currently, all the supported dialects (postgres, oracle, mysql) are written so that ORMJson is assumed to be a json type. If this code is changed, we can use JsonbMap as well.

func CreateORMJson

func CreateORMJson(i interface{}) ORMJson

Creates a postgres JSON from an interface

func (*ORMJson) Scan

func (j *ORMJson) Scan(src interface{}) error

func (ORMJson) Value

func (j ORMJson) Value() (val driver.Value, err error)

type Primary

type Primary uint

Represents a database agnostic primary key

func (*Primary) Foreign

func (x *Primary) Foreign() Foreign

func (*Primary) Scan

func (x *Primary) Scan(src interface{}) error

func (*Primary) Uint

func (x *Primary) Uint() uint

func (*Primary) Value

func (x *Primary) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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