dbcommon

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 13 Imported by: 76

Documentation

Overview

Package dbcommon provides common database functionality

Index

Constants

This section is empty.

Variables

View Source
var AllDBTypes []DBType

AllDBTypes is a list of all contract types. Since we use stringer and this is a testing library, instead of manually copying all these out we pull the names out of stringer. In order to make sure stringer is updated, we panic on any method called where the index is higher than the stringer array length.

Functions

func GetGormLogger

func GetGormLogger(zapLogger *log.ZapEventLogger) gormLogger.Interface

GetGormLogger gets a gorm logger at the correct level TODO investigate https://github.com/moul/zapgorm, we want to use the same write group.

Types

type DBType

type DBType int

DBType is the database driver to use.

const (
	// Mysql is a mysql base db.
	Mysql DBType = 0 // mysql
	// Sqlite file based db.
	Sqlite DBType = iota // sqlite
	// Clickhouse performant db by yandex.
	Clickhouse DBType = iota // clickhouse
)

func DBTypeFromString

func DBTypeFromString(str string) (DBType, error)

DBTypeFromString parses a database type from a string.

func (DBType) String

func (i DBType) String() string

type Namer

type Namer struct {
	// contains filtered or unexported fields
}

Namer is used to pull consistent names for fields from models. This prevents inconsistency by panicing on breaking changes. It also allows us to avoid using xModelFieldName, yModelFieldName by taking advantage of introspection.

func NewNamer

func NewNamer(models []interface{}) Namer

NewNamer creates a new namer.

func (Namer) GetConsistentName

func (n Namer) GetConsistentName(fieldName string) string

GetConsistentName makes sure a `ColumnName` has a common column tag against all models we use this so we don't have to define bridgeRedeemModelFieldName, originChainFieldName, etc. panic's on an inconsistency. Note: this should only be called from init.

after this is called, you can safely call getGormFieldName(AnyModelWithField, fieldName) if all fields cannot make this guarantee, they should be separated out to avoid developer confusion.

this returns the result of getGormFieldName for a valid model. It also panics if no model is valid todo consider generating getters for all field names.

Jump to

Keyboard shortcuts

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