database

package
v0.0.0-...-8ad1ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoActionType        ActionTypeEnum = "NO_ACTION"
	RedeemedActionType                 = "REDEEMED"
	RecalledActionType                 = "RECALLED"
	CancelledActionType                = "CANCELLED"
)
View Source
const (
	TransactionStateStarted   TransactionStateEnum = "STARTED"
	TransactionStateProcesing                      = "PROCESSING"
	TransactionStateFinished                       = "FINISHED"
	TransactionStateExpired                        = "EXPIRED"
	TransactionStateFailed                         = "FAILED"
)
View Source
const (
	OwnedItemStatusOwned     OwnedItemStatusEnum = "OWNED"
	OwnedItemStatusUsed                          = "USED"
	OwnedItemStatusWithdrawn                     = "WITHDRAWN"
	OwnedItemStatusReturned                      = "RETURNED"
)

Variables

View Source
var ErrInvalidCoordinates = errors.New("Invalid coordinates")

Functions

func AutoMigrate

func AutoMigrate(db GormDB) error

func GetAllEntities

func GetAllEntities() []interface{}

Types

type ActionTypeEnum

type ActionTypeEnum string

type Business

type Business struct {
	gorm.Model
	PublicId       string         `gorm:"uniqueIndex;not null"`
	OwnerId        uint           `gorm:"not null"`
	Name           string         `gorm:"not null"`
	Description    string         `gorm:"not null"`
	Address        string         `gorm:"not null"`
	GPSCoordinates GPSCoordinates `gorm:"type:geography(POINT,4326);index:,type:gist"`
	NIP            string         `gorm:"unique;not null"`
	KRS            string         `gorm:"unique"`
	REGON          string         `gorm:"unique"`
	OwnerName      string         `gorm:"not null"`
	BannerImageId  string         `gorm:"unique;not null"`
	IconImageId    string         `gorm:"unique;not null"`

	ItemDefinitions []ItemDefinition `gorm:"foreignkey:BusinessId"`
	MenuImages      []MenuImage      `gorm:"foreignkey:BusinessId"`
	VirtualCards    []VirtualCard    `gorm:"foreignkey:BusinessId"`

	User *User `gorm:"foreignkey:OwnerId"`
}

NOTE index is created in automigrate. couldn't figure out how to create a gin fulltext on many columns from tags alone. INDEX NAME is business_fulltext_idx

func (*Business) GetUserId

func (entity *Business) GetUserId(_ GormDB) (uint, error)

type FileMetadata

type FileMetadata struct {
	gorm.Model
	PublicId    string `gorm:"uniqueIndex;not null"`
	OwnerId     uint   `gorm:"not null"`
	ContentType sql.NullString
	Uploaded    sql.NullTime

	User *User `gorm:"foreignkey:OwnerId"`
}

func (*FileMetadata) GetUserId

func (entity *FileMetadata) GetUserId(_ GormDB) (uint, error)

type GPSCoordinates

type GPSCoordinates geom.Point

func FromCoords

func FromCoords(longitude float64, latitude float64) GPSCoordinates

func GPSCoordinatesFromString

func GPSCoordinatesFromString(coords string) (GPSCoordinates, error)

func (GPSCoordinates) GormDataType

func (g GPSCoordinates) GormDataType() string

func (GPSCoordinates) GormValue

func (g GPSCoordinates) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

func (*GPSCoordinates) Scan

func (g *GPSCoordinates) Scan(input interface{}) error

func (*GPSCoordinates) ToString

func (g *GPSCoordinates) ToString() string

func (GPSCoordinates) Value

func (g GPSCoordinates) Value() (driver.Value, error)

// TODO probably does not work

type GormDB

type GormDB interface {
	AddError(err error) error
	Assign(attrs ...interface{}) (tx GormDB)
	Association(column string) *Association
	Attrs(attrs ...interface{}) (tx GormDB)
	AutoMigrate(dst ...interface{}) error
	Begin(opts ...*sql.TxOptions) GormDB
	//tldr we cant use callbacks now
	//Callback() *callbacks
	Clauses(conds ...clause.Expression) (tx GormDB)
	Commit() GormDB
	Connection(fc func(tx GormDB) error) (err error)
	Count(count *int64) (tx GormDB)
	Create(value interface{}) (tx GormDB)
	CreateInBatches(value interface{}, batchSize int) (tx GormDB)
	DB() (*sql.DB, error)
	Debug() (tx GormDB)
	Delete(value interface{}, conds ...interface{}) (tx GormDB)
	Distinct(args ...interface{}) (tx GormDB)
	Exec(sql string, values ...interface{}) (tx GormDB)
	Find(dest interface{}, conds ...interface{}) (tx GormDB)
	FindInBatches(dest interface{}, batchSize int, fc func(tx GormDB, batch int) error) GormDB
	First(dest interface{}, conds ...interface{}) (tx GormDB)
	FirstOrCreate(dest interface{}, conds ...interface{}) (tx GormDB)
	FirstOrInit(dest interface{}, conds ...interface{}) (tx GormDB)
	Get(key string) (interface{}, bool)
	Group(name string) (tx GormDB)
	Having(query interface{}, args ...interface{}) (tx GormDB)
	InnerJoins(query string, args ...interface{}) (tx GormDB)
	InstanceGet(key string) (interface{}, bool)
	InstanceSet(key string, value interface{}) GormDB
	Joins(query string, args ...interface{}) (tx GormDB)
	Last(dest interface{}, conds ...interface{}) (tx GormDB)
	Limit(limit int) (tx GormDB)
	Migrator() Migrator
	Model(value interface{}) (tx GormDB)
	Not(query interface{}, args ...interface{}) (tx GormDB)
	Offset(offset int) (tx GormDB)
	Omit(columns ...string) (tx GormDB)
	Or(query interface{}, args ...interface{}) (tx GormDB)
	Order(value interface{}) (tx GormDB)
	Pluck(column string, dest interface{}) (tx GormDB)
	Preload(query string, args ...interface{}) (tx GormDB)
	Raw(sql string, values ...interface{}) (tx GormDB)
	Rollback() GormDB
	RollbackTo(name string) GormDB
	Row() *sql.Row
	Rows() (*sql.Rows, error)
	Save(value interface{}) (tx GormDB)
	SavePoint(name string) GormDB
	Scan(dest interface{}) (tx GormDB)
	ScanRows(rows *sql.Rows, dest interface{}) error
	Scopes(funcs ...func(GormDB) GormDB) (tx GormDB)
	Select(query interface{}, args ...interface{}) (tx GormDB)
	Session(config *Session) GormDB
	Set(key string, value interface{}) GormDB
	SetupJoinTable(model interface{}, field string, joinTable interface{}) error
	Table(name string, args ...interface{}) (tx GormDB)
	Take(dest interface{}, conds ...interface{}) (tx GormDB)
	ToSQL(queryFn func(tx GormDB) GormDB) string
	Transaction(fc func(tx GormDB) error, opts ...*sql.TxOptions) (err error)
	Unscoped() (tx GormDB)
	Update(column string, value interface{}) (tx GormDB)
	UpdateColumn(column string, value interface{}) (tx GormDB)
	UpdateColumns(values interface{}) (tx GormDB)
	Updates(values interface{}) (tx GormDB)
	Use(plugin Plugin) error
	Where(query interface{}, args ...interface{}) (tx GormDB)
	WithContext(ctx context.Context) GormDB

	GetConfig() *Config
	GetError() error
	GetRowsAffected() int64
	GetStatement() *Statement
}

type GormDBImpl

type GormDBImpl struct {
	Db *DB
}

func (*GormDBImpl) AddError

func (self *GormDBImpl) AddError(err error) error

func (*GormDBImpl) Assign

func (self *GormDBImpl) Assign(attrs ...interface{}) (tx GormDB)

func (*GormDBImpl) Association

func (self *GormDBImpl) Association(column string) *Association

func (*GormDBImpl) Attrs

func (self *GormDBImpl) Attrs(attrs ...interface{}) (tx GormDB)

func (*GormDBImpl) AutoMigrate

func (self *GormDBImpl) AutoMigrate(dst ...interface{}) error

func (*GormDBImpl) Begin

func (self *GormDBImpl) Begin(opts ...*sql.TxOptions) GormDB

func (*GormDBImpl) Clauses

func (self *GormDBImpl) Clauses(conds ...clause.Expression) (tx GormDB)

func (*GormDBImpl) Commit

func (self *GormDBImpl) Commit() GormDB

func (*GormDBImpl) Connection

func (self *GormDBImpl) Connection(fc func(tx GormDB) error) (err error)

func (*GormDBImpl) Count

func (self *GormDBImpl) Count(count *int64) (tx GormDB)

func (*GormDBImpl) Create

func (self *GormDBImpl) Create(value interface{}) (tx GormDB)

func (*GormDBImpl) CreateInBatches

func (self *GormDBImpl) CreateInBatches(value interface{}, batchSize int) (tx GormDB)

func (*GormDBImpl) DB

func (self *GormDBImpl) DB() (*sql.DB, error)

func (*GormDBImpl) Debug

func (self *GormDBImpl) Debug() (tx GormDB)

func (*GormDBImpl) Delete

func (self *GormDBImpl) Delete(value interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) Distinct

func (self *GormDBImpl) Distinct(args ...interface{}) (tx GormDB)

func (*GormDBImpl) Exec

func (self *GormDBImpl) Exec(sql string, values ...interface{}) (tx GormDB)

func (*GormDBImpl) Find

func (self *GormDBImpl) Find(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) FindInBatches

func (self *GormDBImpl) FindInBatches(dest interface{}, batchSize int, fc func(tx GormDB, batch int) error) GormDB

func (*GormDBImpl) First

func (self *GormDBImpl) First(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) FirstOrCreate

func (self *GormDBImpl) FirstOrCreate(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) FirstOrInit

func (self *GormDBImpl) FirstOrInit(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) Get

func (self *GormDBImpl) Get(key string) (interface{}, bool)

func (*GormDBImpl) GetConfig

func (self *GormDBImpl) GetConfig() *Config

func (*GormDBImpl) GetError

func (self *GormDBImpl) GetError() error

func (*GormDBImpl) GetRowsAffected

func (self *GormDBImpl) GetRowsAffected() int64

func (*GormDBImpl) GetStatement

func (self *GormDBImpl) GetStatement() *Statement

func (*GormDBImpl) Group

func (self *GormDBImpl) Group(name string) (tx GormDB)

func (*GormDBImpl) Having

func (self *GormDBImpl) Having(query interface{}, args ...interface{}) (tx GormDB)

func (*GormDBImpl) InnerJoins

func (self *GormDBImpl) InnerJoins(query string, args ...interface{}) (tx GormDB)

func (*GormDBImpl) InstanceGet

func (self *GormDBImpl) InstanceGet(key string) (interface{}, bool)

func (*GormDBImpl) InstanceSet

func (self *GormDBImpl) InstanceSet(key string, value interface{}) GormDB

func (*GormDBImpl) Joins

func (self *GormDBImpl) Joins(query string, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Last

func (self *GormDBImpl) Last(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) Limit

func (self *GormDBImpl) Limit(limit int) (tx GormDB)

func (*GormDBImpl) Migrator

func (self *GormDBImpl) Migrator() Migrator

func (*GormDBImpl) Model

func (self *GormDBImpl) Model(value interface{}) (tx GormDB)

func (*GormDBImpl) Not

func (self *GormDBImpl) Not(query interface{}, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Offset

func (self *GormDBImpl) Offset(offset int) (tx GormDB)

func (*GormDBImpl) Omit

func (self *GormDBImpl) Omit(columns ...string) (tx GormDB)

func (*GormDBImpl) Or

func (self *GormDBImpl) Or(query interface{}, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Order

func (self *GormDBImpl) Order(value interface{}) (tx GormDB)

func (*GormDBImpl) Pluck

func (self *GormDBImpl) Pluck(column string, dest interface{}) (tx GormDB)

func (*GormDBImpl) Preload

func (self *GormDBImpl) Preload(query string, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Raw

func (self *GormDBImpl) Raw(sql string, values ...interface{}) (tx GormDB)

func (*GormDBImpl) Rollback

func (self *GormDBImpl) Rollback() GormDB

func (*GormDBImpl) RollbackTo

func (self *GormDBImpl) RollbackTo(name string) GormDB

func (*GormDBImpl) Row

func (self *GormDBImpl) Row() *sql.Row

func (*GormDBImpl) Rows

func (self *GormDBImpl) Rows() (*sql.Rows, error)

func (*GormDBImpl) Save

func (self *GormDBImpl) Save(value interface{}) (tx GormDB)

func (*GormDBImpl) SavePoint

func (self *GormDBImpl) SavePoint(name string) GormDB

func (*GormDBImpl) Scan

func (self *GormDBImpl) Scan(dest interface{}) (tx GormDB)

func (*GormDBImpl) ScanRows

func (self *GormDBImpl) ScanRows(rows *sql.Rows, dest interface{}) error

func (*GormDBImpl) Scopes

func (self *GormDBImpl) Scopes(funcs ...func(GormDB) GormDB) (tx GormDB)

func (*GormDBImpl) Select

func (self *GormDBImpl) Select(query interface{}, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Session

func (self *GormDBImpl) Session(config *Session) GormDB

func (*GormDBImpl) Set

func (self *GormDBImpl) Set(key string, value interface{}) GormDB

func (*GormDBImpl) SetupJoinTable

func (self *GormDBImpl) SetupJoinTable(model interface{}, field string, joinTable interface{}) error

func (*GormDBImpl) Table

func (self *GormDBImpl) Table(name string, args ...interface{}) (tx GormDB)

func (*GormDBImpl) Take

func (self *GormDBImpl) Take(dest interface{}, conds ...interface{}) (tx GormDB)

func (*GormDBImpl) ToSQL

func (self *GormDBImpl) ToSQL(queryFn func(tx GormDB) GormDB) string

func (*GormDBImpl) Transaction

func (self *GormDBImpl) Transaction(fc func(tx GormDB) error, opts ...*sql.TxOptions) (err error)

func (*GormDBImpl) Unscoped

func (self *GormDBImpl) Unscoped() (tx GormDB)

func (*GormDBImpl) Update

func (self *GormDBImpl) Update(column string, value interface{}) (tx GormDB)

func (*GormDBImpl) UpdateColumn

func (self *GormDBImpl) UpdateColumn(column string, value interface{}) (tx GormDB)

func (*GormDBImpl) UpdateColumns

func (self *GormDBImpl) UpdateColumns(values interface{}) (tx GormDB)

func (*GormDBImpl) Updates

func (self *GormDBImpl) Updates(values interface{}) (tx GormDB)

func (*GormDBImpl) Use

func (self *GormDBImpl) Use(plugin Plugin) error

func (*GormDBImpl) Where

func (self *GormDBImpl) Where(query interface{}, args ...interface{}) (tx GormDB)

func (*GormDBImpl) WithContext

func (self *GormDBImpl) WithContext(ctx context.Context) GormDB

type ItemDefinition

type ItemDefinition struct {
	gorm.Model
	PublicId    string `gorm:"uniqueIndex;not null"`
	BusinessId  uint   `gorm:"not null"`
	Name        string `gorm:"not null"`
	Price       uint   `gorm:"not null"`
	Description string `gorm:"not null"`
	ImageId     string `gorm:"unique"`
	StartDate   sql.NullTime
	EndDate     sql.NullTime
	MaxAmount   uint
	Available   bool `gorm:"not null"`
	Withdrawn   bool `gorm:"not null"`

	OwnedItems []OwnedItem `gorm:"foreignkey:DefinitionId"`

	Business *Business `gorm:"foreignkey:BusinessId"`
}

func (*ItemDefinition) GetBusinessId

func (entity *ItemDefinition) GetBusinessId(_ GormDB) (uint, error)

type LocalCard

type LocalCard struct {
	gorm.Model
	PublicId string `gorm:"uniqueIndex;not null"`
	OwnerId  uint
	Type     string
	Code     string
	Name     string

	User *User `gorm:"foreignkey:OwnerId"`
}

func (*LocalCard) GetUserId

func (entity *LocalCard) GetUserId(_ GormDB) (uint, error)
type MenuImage struct {
	gorm.Model
	BusinessId uint   `gorm:"uniqueIndex:menu_item_idx;not null"`
	FileId     string `gorm:"uniqueIndex:menu_item_idx;not null"`

	Business *Business `gorm:"foreignkey:BusinessId"`
}
func (entity *MenuImage) GetBusinessId(_ GormDB) (uint, error)

type OwnedItem

type OwnedItem struct {
	gorm.Model
	PublicId      string `gorm:"uniqueIndex;not null"`
	DefinitionId  uint   `gorm:"not null"`
	VirtualCardId uint   `gorm:"not null"`
	Used          sql.NullTime
	Status        OwnedItemStatusEnum `gorm:"default:OWNED;not null"`

	ItemDefinition *ItemDefinition `gorm:"foreignkey:DefinitionId"`
	VirtualCard    *VirtualCard    `gorm:"foreignkey:VirtualCardId"`
}

func (*OwnedItem) GetBusinessId

func (entity *OwnedItem) GetBusinessId(db GormDB) (uint, error)

func (*OwnedItem) GetUserId

func (entity *OwnedItem) GetUserId(db GormDB) (uint, error)

type OwnedItemStatusEnum

type OwnedItemStatusEnum string

type Token

type Token struct {
	gorm.Model
	OwnerId      uint
	TokenId      string           `gorm:"uniqueIndex;not null"`
	TokenHash    string           `gorm:"not null"`
	Expires      time.Time        `gorm:"not null"`
	TokenPurpose TokenPurposeEnum `gorm:"not null"`
	Used         bool             `gorm:"default:false;not null"`
	Recalled     bool             `gorm:"default:false;not null"`

	User *User `gorm:"foreignkey:OwnerId"`
}

func (*Token) GetUserId

func (entity *Token) GetUserId(_ GormDB) (uint, error)

type TokenPurposeEnum

type TokenPurposeEnum string
const (
	TokenPurposeSession TokenPurposeEnum = "SESSION"
	TokenPurposeEmail   TokenPurposeEnum = "EMAIL"
)

type Transaction

type Transaction struct {
	gorm.Model
	PublicId      string               `gorm:"uniqueIndex;not null"`
	VirtualCardId uint                 `gorm:"index:code,unique,priority:1;not null"`
	Code          string               `gorm:"index:code,unique,priority:2;not null"`
	State         TransactionStateEnum `gorm:"default:STARTED;not null"`
	AddedPoints   uint

	TransactionDetails []TransactionDetail `gorm:"foreignkey:TransactionId"`

	VirtualCard *VirtualCard `gorm:"foreignkey:VirtualCardId"`
}

func (*Transaction) GetBusinessId

func (entity *Transaction) GetBusinessId(db GormDB) (uint, error)

func (*Transaction) GetUserId

func (entity *Transaction) GetUserId(db GormDB) (uint, error)

type TransactionDetail

type TransactionDetail struct {
	gorm.Model
	TransactionId uint           `gorm:"index:transaction_detail,unique,priority:1;not null"`
	ItemId        uint           `gorm:"index:transaction_detail,unique,priority:2;not null"`
	Action        ActionTypeEnum `gorm:"default:NO_ACTION;not null"`

	Transaction *Transaction `gorm:"foreignkey:TransactionId"`
	OwnedItem   *OwnedItem   `gorm:"foreignkey:ItemId"`
}

type TransactionStateEnum

type TransactionStateEnum string

type User

type User struct {
	gorm.Model
	PublicId string `gorm:"uniqueIndex;not null"`
	//FirstName     string `gorm:"not null"`
	//LastName      string `gorm:"not null"`
	Email         string `gorm:"uniqueIndex;not null"`
	PasswordHash  string `gorm:"not null"`
	EmailVerified bool   `gorm:"default:false;not null"`

	Tokens        []Token        `gorm:"foreignkey:OwnerId"`
	FilesMetadata []FileMetadata `gorm:"foreignkey:OwnerId"`
	LocalCards    []LocalCard    `gorm:"foreignkey:OwnerId"`
	VirtualCards  []VirtualCard  `gorm:"foreignkey:OwnerId"`
	Business      *Business      `gorm:"foreignkey:OwnerId"`
}

type VirtualCard

type VirtualCard struct {
	gorm.Model
	PublicId   string `gorm:"uniqueIndex;not null"`
	OwnerId    uint   `gorm:"not null"`
	BusinessId uint   `gorm:"not null"`
	Points     uint   `gorm:"not null"`

	OwnedItems   []OwnedItem   `gorm:"foreignkey:VirtualCardId"`
	Transactions []Transaction `gorm:"foreignkey:VirtualCardId"`

	Business *Business `gorm:"foreignkey:BusinessId"`
	User     *User     `gorm:"foreignkey:OwnerId"`
}

func (*VirtualCard) GetBusinessId

func (entity *VirtualCard) GetBusinessId(_ GormDB) (uint, error)

func (*VirtualCard) GetUserId

func (entity *VirtualCard) GetUserId(_ GormDB) (uint, error)

Directories

Path Synopsis
mocks
Package mock_accessors is a generated GoMock package.
Package mock_accessors is a generated GoMock package.
Package mock_database is a generated GoMock package.
Package mock_database is a generated GoMock package.

Jump to

Keyboard shortcuts

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