model

package
v0.0.0-...-1a1dcb8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgs  = errors.New("Invalid Args")
	ErrKeyConflict  = errors.New("Key Conflict")
	ErrDataNotFound = errors.New("Record Not Found")
	ErrUserExists   = errors.New("User already exists")
	ErrUnknown      = errors.New("Unknown Error")
	ErrFailed       = errors.New("Failed")
)

Model errors

Functions

func DB

func DB() *gorm.DB

DB returns the database instance

Types

type DBInstance

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

DBInstance is a singleton DB instance

func (*DBInstance) Instance

func (i *DBInstance) Instance() any

Instance gets the singleton instance

type User

type User struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	Name      string    `json:"name"`
	Email     string    `json:"email"`
	Password  string    `json:"-"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

User the user model

func LoginByEmailAndPassword

func LoginByEmailAndPassword(email, password string) (*User, error)

LoginByEmailAndPassword login a user by his email and password

func (*User) Create

func (u *User) Create() error

Create a new user

func (*User) GetFirstByEmail

func (u *User) GetFirstByEmail(email string) error

GetFirstByEmail gets the user by his email

func (*User) GetFirstByID

func (u *User) GetFirstByID(id string) error

GetFirstByID gets the user by his ID

func (*User) Login

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

Login a user

func (*User) Signup

func (u *User) Signup() error

Signup a new user

func (User) TableName

func (User) TableName() string

TableName for gorm

Jump to

Keyboard shortcuts

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