database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *gorm.DB

Functions

func ConnectDatabase

func ConnectDatabase(openDatabase OpenDatabaseFunc) (*gorm.DB, error)

func InitDatabase

func InitDatabase(openDatabase OpenDatabaseFunc)

Types

type FollowDTO

type FollowDTO struct {
	WhoId int64   `gorm:"not null;index;index:who_id_whom_id"`
	Who   UserDTO `gorm:"primaryKey;foreignkey:WhoId"`

	WhomId int64   `gorm:"not null;index:who_id_whom_id"`
	Whom   UserDTO `gorm:"primaryKey;foreignkey:WhomId"`
}

func (FollowDTO) TableName

func (FollowDTO) TableName() string

type GormLatestRepository

type GormLatestRepository struct {
	// contains filtered or unexported fields
}

func NewGormLatestRepository

func NewGormLatestRepository(db *gorm.DB) *GormLatestRepository

func (*GormLatestRepository) GetCurrent

func (rep *GormLatestRepository) GetCurrent() (int, error)

func (*GormLatestRepository) Migrate

func (rep *GormLatestRepository) Migrate() error

func (*GormLatestRepository) Set

func (rep *GormLatestRepository) Set(newLatest int) error

type GormMessageRepository

type GormMessageRepository struct {
	// contains filtered or unexported fields
}

func NewGormMessageRepository

func NewGormMessageRepository(db *gorm.DB) *GormMessageRepository

func (*GormMessageRepository) Create

func (rep *GormMessageRepository) Create(message models.Message) error

func (*GormMessageRepository) FlagByMsgId

func (rep *GormMessageRepository) FlagByMsgId(msgId int) (models.Message, error)

func (*GormMessageRepository) GetByUserAndItsFollowers

func (rep *GormMessageRepository) GetByUserAndItsFollowers(userId int64, limit int) ([]models.Message, error)

func (*GormMessageRepository) GetByUserId

func (rep *GormMessageRepository) GetByUserId(userId int64, limit int) ([]models.Message, error)

func (*GormMessageRepository) GetWithLimit

func (rep *GormMessageRepository) GetWithLimit(limit int) ([]models.Message, error)

func (*GormMessageRepository) Migrate

func (rep *GormMessageRepository) Migrate() error

type GormUserRepository

type GormUserRepository struct {
	// contains filtered or unexported fields
}

func NewGormUserRepository

func NewGormUserRepository(db *gorm.DB) *GormUserRepository

func (*GormUserRepository) AllFollowed

func (rep *GormUserRepository) AllFollowed(whoId int64) ([]*models.User, error)

func (*GormUserRepository) Create

func (rep *GormUserRepository) Create(user models.User) error

func (*GormUserRepository) Follow

func (rep *GormUserRepository) Follow(whoId int64, whomId int64) error

func (*GormUserRepository) GetByID

func (rep *GormUserRepository) GetByID(id int64) (*models.User, error)

func (*GormUserRepository) GetByUsername

func (rep *GormUserRepository) GetByUsername(username string) (*models.User, error)

func (*GormUserRepository) IsFollowing

func (rep *GormUserRepository) IsFollowing(whoId int64, whomId int64) (bool, error)

func (*GormUserRepository) Migrate

func (rep *GormUserRepository) Migrate() error

func (*GormUserRepository) NumUsers

func (rep *GormUserRepository) NumUsers() (int64, error)

func (*GormUserRepository) Unfollow

func (rep *GormUserRepository) Unfollow(whoId int64, whomId int64) error

type ILatestRepository

type ILatestRepository interface {
	Migrate() error
	Set(newValue int) error
	GetCurrent() (int, error)
}

type IMessageRepository

type IMessageRepository interface {
	Migrate() error
	Create(message models.Message) error
	GetWithLimit(limit int) ([]models.Message, error)
	GetByUserId(userId int64, limit int) ([]models.Message, error)
	GetByUserAndItsFollowers(userId int64, limit int) ([]models.Message, error)
	FlagByMsgId(msgId int) (models.Message, error)
}

type IUserRepository

type IUserRepository interface {
	Migrate() error
	Create(users models.User) error
	GetByID(id int64) (*models.User, error)
	GetByUsername(username string) (*models.User, error)
	NumUsers() (int64, error)

	Follow(whoId int64, whomId int64) error
	Unfollow(whoId int64, whomId int64) error
	IsFollowing(whoId int64, whomId int64) (bool, error)
	AllFollowed(whoId int64) ([]*models.User, error)
}

type LatestDTO

type LatestDTO struct {
	Id    int `gorm:"primaryKey,autoIncrement"`
	Value int `gorm:"not null"`
}

func (LatestDTO) TableName

func (LatestDTO) TableName() string

type MessageDTO

type MessageDTO struct {
	gorm.Model

	AuthorId int     `gorm:"not null;index"`
	Author   UserDTO `gorm:"foreignkey:AuthorId"`
	Text     string  `gorm:"not null"`
	PubDate  int64   `gorm:"not null;index:,sort:desc"`
	Flagged  bool    `gorm:"not null"`
}

func (MessageDTO) TableName

func (MessageDTO) TableName() string

type OpenDatabaseFunc

type OpenDatabaseFunc = func() gorm.Dialector

type UserDTO

type UserDTO struct {
	gorm.Model

	Username     string `gorm:"not null;index"`
	Email        string `gorm:"not null"`
	PasswordHash string `gorm:"not null"`

	Followed  []FollowDTO `gorm:"foreignkey:WhoId"`
	Followers []FollowDTO `gorm:"foreignkey:WhomId"`
}

func (UserDTO) TableName

func (UserDTO) TableName() string

Jump to

Keyboard shortcuts

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