database

package
v0.0.0-...-c791c95 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package database implements postgres connection, schema, and migration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect() (*gorm.DB, error)

Connect opens a database connection and returns it.

func GetConnection

func GetConnection() (*gorm.DB, error)

GetConnection returns an existing connection, otherwise opens a new one.

func IsRecordNotFoundError

func IsRecordNotFoundError(err error) bool

IsRecordNotFoundError returns true if error contains a RecordNotFound error.

func Migrate

func Migrate() error

Migrate automatically migrates the database to the latest schema.

Types

type Role

type Role struct {
	gorm.Model
	Role        string `gorm:"type:varchar(32);unique_index;not null"`
	Permissions string
}

Role details.

type TokenRevocation

type TokenRevocation struct {
	gorm.Model
	UserID          uint `gorm:"not null"`
	RefreshToken    string
	RevokeAllBefore time.Time
}

TokenRevocation details.

type User

type User struct {
	gorm.Model
	RoleID                   uint   `gorm:"not null"`
	Email                    string `gorm:"type:varchar(128);unique_index;not null"`
	Username                 string `gorm:"type:varchar(40);unique_index;not null"`
	Password                 string `gorm:"type:varchar(60);not null"`
	FirstName                string `gorm:"type:varchar(32);not null"`
	LastName                 string `gorm:"type:varchar(32);not null"`
	IsConfirmedEmail         bool   `gorm:"not null;default:false"`
	IsActive                 bool   `gorm:"not null;default:true"`
	ConfirmEmailToken        string
	ConfirmEmailTokenExpires time.Time
	ResetPassToken           string
	ResetPassTokenExpires    time.Time
	LastSignin               time.Time
	FailedSignin             time.Time
}

User details.

func (*User) BeforeSave

func (u *User) BeforeSave()

BeforeSave for User.

Jump to

Keyboard shortcuts

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