db

package
v0.0.0-...-796150a Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	Name     string
	User     string
	Password string
}

Config defines the parameters for creating Conn instances.

type Conn

type Conn struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Conn maintains a connection to the database.

func New

func New(cfg *Config) (*Conn, error)

New attempts to connect to the database.

func (*Conn) Close

func (c *Conn) Close()

Close closes the database connection.

func (*Conn) Migrate

func (c *Conn) Migrate() error

Migrate applies all pending database migrations.

func (*Conn) Transaction

func (c *Conn) Transaction(fn func(*Conn) error) error

Transaction runs the specified function in a transaction.

type Member

type Member struct {
	ID      int64 `json:"id"`
	UserID  int64 `gorm:"not null" json:"-"`
	User    *User `gorm:"constraint:OnDelete:CASCADE" json:"user,omitempty"`
	RoomID  int64 `gorm:"not null" json:"-"`
	Room    *Room `gorm:"constraint:OnDelete:CASCADE" json:"room"`
	IsOwner bool  `gorm:"not null" json:"is_owner"`
	IsAdmin bool  `gorm:"not null" json:"is_admin"`
}

Member represents a member of a specific room.

type Message

type Message struct {
	ID           int64     `json:"id"`
	MemberID     int64     `gorm:"not null" json:"-"`
	Member       *Member   `gorm:"constraint:OnDelete:CASCADE" json:"member"`
	Body         string    `gorm:"not null" json:"body"`
	CreationDate time.Time `gorm:"not null" json:"creation_date"`
	StarCount    int64     `gorm:"not null" json:"star_count"`
	Stars        []*User   `gorm:"many2many:message_stars;" json:"-"`
	IsEdited     bool      `gorm:"not null" json:"is_edited"`
}

Message represents an individual message.

type Room

type Room struct {
	ID           int64     `json:"id"`
	Name         string    `gorm:"not null" json:"name"`
	CreationDate time.Time `gorm:"not null" json:"creation_date"`
}

Room represents a chat group.

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `gorm:"not null;uniqueIndex" json:"username"`
	Password string `gorm:"not null" json:"-"`
	Email    string `gorm:"not null" json:"email"`
	IsActive bool   `gorm:"not null" json:"is_active"`
}

User represents a registered user.

func (*User) Authenticate

func (u *User) Authenticate(password string) error

Authenticate compares the provided password to the one stored in the database. An error is returned if the values do not match.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword salts and hashes the user's password. It does not store the new value in the database.

Jump to

Keyboard shortcuts

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