models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTables

func CreateTables(drop_if_exists bool)

CreateTables will AutoMigrate all tables in application. If drop_if_exists is set to true, it will drop all tables before creating.

func GetDB

func GetDB() *gorm.DB

Get the current db struct

func InitializeDB

func InitializeDB()

IntializeDB reads all credentials in environments variable and creates a connection to the DB. It also creates a logs directory and a log file to save all errors in the application.

Types

type Chat

type Chat struct {
	gorm.Model
	RoomID  uint `gorm:"not null"`
	Room    Room
	UserID  uint `gorm:"not null"`
	User    User
	Message string `gorm:"not null"`
}

type DetailedRoom

type DetailedRoom struct {
	UserID uint `gorm:"primaryKey"`
	RoomID uint `gorm:"primaryKey"`

	User User
	Room Room
}

type Room

type Room struct {
	gorm.Model
	Users []*User `gorm:"many2many:detailed_rooms"`
}

type User

type User struct {
	gorm.Model
	Username *string `gorm:"unique;not null"`
	Password *string `gorm:"not null"`
	Role     *string `gorm:"not null;check:role in ('member', 'mod', 'admin')"`
	Age      *uint
	Gender   *string `gorm:"check:gender in ('male', 'female', 'gay', 'les', 'other')"`
	Rooms    []*Room `gorm:"many2many:detailed_rooms"`
}

Jump to

Keyboard shortcuts

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