gormkeyvalue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 10 Imported by: 0

README

gorm-key-value

When you're tired of writing a database from scratch every time. Finally, a ready lib!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDBConnectionURI

func GetDBConnectionURI(cfg DBConfig) string

Types

type DBConfig

type DBConfig struct {
	Host          string `json:"DB_HOST" envconfig:"DB_HOST" default:"localhost"`
	Port          int    `json:"DB_PORT" envconfig:"DB_PORT" default:"3306"`
	Name          string `json:"DB_NAME" envconfig:"DB_NAME" required:"true"`
	User          string `json:"DB_USER" envconfig:"DB_USER" required:"true"`
	Password      string `json:"DB_PASSWORD" envconfig:"DB_PASSWORD" default:""`
	ConnTimeoutMS int    `json:"DB_CONN_TIMEOUT" envconfig:"DB_CONN_TIMEOUT" default:"5000"`
	TablePrefix   string `json:"DB_TABLE_PREFIX" envconfig:"DB_TABLE_PREFIX" default:""`

	MaxOpenConns        int `json:"DB_MAX_OPEN_CONNS" envconfig:"DB_MAX_OPEN_CONNS" default:"10"`
	MaxIdleConns        int `json:"DB_MAX_IDLE_CONNS" envconfig:"DB_MAX_IDLE_CONNS" default:"5"`
	ConnMaxLifetimeMins int `json:"DB_CONN_MAX_LIFETIME_MINS" envconfig:"DB_CONN_MAX_LIFETIME_MINS" default:"5"`

	GormDebugMode bool   `json:"DB_GORM_DEBUG_MODE" envconfig:"DB_GORM_DEBUG_MODE" default:"false"`
	Location      string `json:"DB_TIME_LOCATION" envconfig:"DB_TIME_LOCATION" default:"Europe/Moscow"`
}

type Entry

type Entry struct {
	ID        uint64    `gorm:"primarykey"`
	CreatedAt time.Time `gorm:"index"`
	UpdatedAt time.Time `gorm:"index"`

	Key   string `gorm:"index"`
	Name  string `gorm:"index"`
	Value []byte `gorm:"type:json"`
}

type Memory

type Memory interface {
	IsEntryExists(Entry) (bool, error)
	GetAllEntrys() ([]Entry, error)
	GetEntrysLikeName(namePattern string) ([]Entry, error)
	GetEntry(key string) (Entry, error)
	SaveEntry(e Entry) error
}

func New

func New(cfg DBConfig) (Memory, error)

Jump to

Keyboard shortcuts

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