database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dialector gorm.Dialector) (*gorm.DB, error)

Open returns a new database instance.

Types

type Repo

type Repo struct {
	// UserID is the owner's ID.
	UserID uint `gorm:"index:name_user_id,unique"`
	// Name is the repository name.
	Name string `gorm:"index:name_user_id,unique"`
	// Description is the repository description.
	Description string
	// User is the owner of the repository.
	User User
	// CID is the content identifier of the repository.
	CID string

	gorm.Model
}

Repo contains repository info.

func (*Repo) BeforeSave

func (r *Repo) BeforeSave(tx *gorm.DB) error

BeforeSave validates fields before saving.

func (*Repo) Create

func (r *Repo) Create(db *gorm.DB) error

func (*Repo) Find

func (r *Repo) Find(db *gorm.DB, id interface{}) error

func (*Repo) FindByNameAndUserID

func (r *Repo) FindByNameAndUserID(db *gorm.DB, name string, userID uint) error

func (*Repo) UpdateCID

func (r *Repo) UpdateCID(db *gorm.DB) error

type Session

type Session struct {
	// ID is the unique session ID.
	ID string `gorm:"primaryKey"`
	// UserID is the owner's ID.
	UserID uint `gorm:"index"`
	// User is the session user.
	User User
	// CreatedAt is the time the session was created.
	CreatedAt time.Time
	// UpdatedAt is the time the session was updated.
	UpdatedAt time.Time
}

Session contains session details.

func (*Session) BeforeCreate

func (s *Session) BeforeCreate(tx *gorm.DB) error

BeforeCreate validates fields before creating.

func (*Session) Create

func (s *Session) Create(db *gorm.DB) error

func (*Session) Find

func (s *Session) Find(db *gorm.DB, id string) error

type User

type User struct {
	// Username is an alias for the user.
	Username string `gorm:"uniqueIndex"`
	// Email is the account email address.
	Email string `gorm:"uniqueIndex"`
	// Password is the plain text password.
	Password string `gorm:"-"`
	// PasswordHash contains the hased password.
	PasswordHash []byte

	gorm.Model
}

User contains account details.

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

BeforeCreate validates fields before creating.

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

BeforeSave validates fields before saving.

func (*User) Create

func (u *User) Create(db *gorm.DB) error

func (*User) Find

func (u *User) Find(db *gorm.DB, id interface{}) error

func (*User) FindByEmail

func (u *User) FindByEmail(db *gorm.DB, email string) error

func (*User) FindByEmailOrUsername

func (u *User) FindByEmailOrUsername(db *gorm.DB, email, username string) error

func (*User) FindByUsername

func (u *User) FindByUsername(db *gorm.DB, username string) error

Jump to

Keyboard shortcuts

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