models

package
v0.0.0-...-45d5ef5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DonationCreationFailure = "failed creating donation in database"
	JSONMarshalFailure      = "failed marshalling JSON data"
)

define error messages

View Source
const (
	ConnectionError = "connection error"
)

define general error messages

Variables

This section is empty.

Functions

func CloseDB

func CloseDB()

CloseDB closes the DB connecton

func ConnectDB

func ConnectDB() error

ConnectDB reads environment variables for DB configuration and attempts to open the connection

func GetDB

func GetDB() *gorm.DB

GetDB returns a handle to the DB object

func InitializeDB

func InitializeDB(quit chan struct{}, errors chan config.ErrorMessage)

InitializeDB connects to the Database and migrates the schema

func InitializeTestDB

func InitializeTestDB()

InitializeTestDB connects to an inmemory sqlite for testing

func MigrateDB

func MigrateDB(debug bool)

MigrateDB Executes Migrations on the database

Types

type BaseModel

type BaseModel struct {
	ID        uuid.UUID `json:"id" gorm:"type:uuid;primary_key;"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

BaseModel defines the basic fields for each other model

func (*BaseModel) BeforeCreate

func (base *BaseModel) BeforeCreate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

type Donation

type Donation struct {
	BaseModel
	Data json.RawMessage `sql:"json"`
}

Donation model

func (*Donation) Create

func (donation *Donation) Create() error

Create creates Donation object in the Database

Jump to

Keyboard shortcuts

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