db

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingDisableSignup    = "disable-signup"
	SettingRequireLogin     = "require-login"
	SettingDisableLoginForm = "disable-login-form"
	SettingDisableGravatar  = "disable-gravatar"
)

Variables

This section is empty.

Functions

func ApplyMigrations

func ApplyMigrations(db *gorm.DB) error

func Close

func Close() error

func CountAll

func CountAll(table interface{}) (int64, error)

func CountAllGistsForkedByUser

func CountAllGistsForkedByUser(fromUserId uint, currentUserId uint) (int64, error)

func CountAllGistsFromUser

func CountAllGistsFromUser(fromUserId uint, currentUserId uint) (int64, error)

func CountAllGistsLikedByUser

func CountAllGistsLikedByUser(fromUserId uint, currentUserId uint) (int64, error)

func GetAllGistsVisibleByUser added in v1.6.0

func GetAllGistsVisibleByUser(userId uint) ([]uint, error)

func GetSetting

func GetSetting(key string) (string, error)

func GetSettings

func GetSettings() (map[string]string, error)

func GetUsersFromEmails

func GetUsersFromEmails(emailsSet map[string]struct{}) (map[string]*User, error)

func InvitationCodeExists added in v1.7.0

func InvitationCodeExists(code string) (bool, error)

func IsUniqueConstraintViolation

func IsUniqueConstraintViolation(err error) bool

func Ping added in v1.6.0

func Ping() error

func SSHKeyLastUsedNow

func SSHKeyLastUsedNow(sshKeyContent string) error

func Setup

func Setup(dbPath string, sharedCache bool) error

func UpdateSetting

func UpdateSetting(key string, value string) error

func UserExists

func UserExists(username string) (bool, error)

Types

type AdminSetting

type AdminSetting struct {
	Key   string `gorm:"uniqueIndex"`
	Value string
}

type FileDTO

type FileDTO struct {
	Filename string `validate:"excludes=\x2f,excludes=\x5c,max=255"`
	Content  string `validate:"required"`
}

type Gist

type Gist struct {
	ID              uint `gorm:"primaryKey"`
	Uuid            string
	Title           string
	URL             string
	Preview         string
	PreviewFilename string
	Description     string
	Private         Visibility // 0: public, 1: unlisted, 2: private
	UserID          uint
	User            User
	NbFiles         int
	NbLikes         int
	NbForks         int
	CreatedAt       int64
	UpdatedAt       int64

	Likes    []User `gorm:"many2many:likes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Forked   *Gist  `gorm:"foreignKey:ForkedID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL"`
	ForkedID uint
}

func GetAllGists

func GetAllGists(offset int) ([]*Gist, error)

func GetAllGistsByIds added in v1.6.0

func GetAllGistsByIds(ids []uint) ([]*Gist, error)

func GetAllGistsForCurrentUser

func GetAllGistsForCurrentUser(currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsForkedByUser

func GetAllGistsForkedByUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsFromSearch

func GetAllGistsFromSearch(currentUserId uint, query string, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsFromUser

func GetAllGistsFromUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsLikedByUser

func GetAllGistsLikedByUser(fromUserId uint, currentUserId uint, offset int, sort string, order string) ([]*Gist, error)

func GetAllGistsRows

func GetAllGistsRows() ([]*Gist, error)

func GetGist

func GetGist(user string, gistUuid string) (*Gist, error)

func GetGistByID

func GetGistByID(gistId string) (*Gist, error)

func (*Gist) AddAndCommitFile added in v1.6.0

func (gist *Gist) AddAndCommitFile(file *FileDTO) error

func (*Gist) AddAndCommitFiles

func (gist *Gist) AddAndCommitFiles(files *[]FileDTO) error

func (*Gist) AddInIndex added in v1.6.0

func (gist *Gist) AddInIndex()

func (*Gist) AppendUserLike

func (gist *Gist) AppendUserLike(user *User) error

func (*Gist) BeforeDelete

func (gist *Gist) BeforeDelete(tx *gorm.DB) error

func (*Gist) CanWrite

func (gist *Gist) CanWrite(user *User) bool

func (*Gist) Create

func (gist *Gist) Create() error

func (*Gist) CreateForked

func (gist *Gist) CreateForked() error

func (*Gist) Delete

func (gist *Gist) Delete() error

func (*Gist) DeleteRepository

func (gist *Gist) DeleteRepository() error

func (*Gist) File

func (gist *Gist) File(revision string, filename string, truncate bool) (*git.File, error)

func (*Gist) FileNames added in v1.6.0

func (gist *Gist) FileNames(revision string) ([]string, error)

func (*Gist) Files

func (gist *Gist) Files(revision string, truncate bool) ([]*git.File, error)

func (*Gist) ForkClone

func (gist *Gist) ForkClone(username string, uuid string) error

func (*Gist) GetForkParent

func (gist *Gist) GetForkParent(user *User) (*Gist, error)

func (*Gist) GetForks

func (gist *Gist) GetForks(currentUserId uint, offset int) ([]*Gist, error)

func (*Gist) GetLanguagesFromFiles added in v1.6.0

func (gist *Gist) GetLanguagesFromFiles() ([]string, error)

func (*Gist) GetUsersLikes

func (gist *Gist) GetUsersLikes(offset int) ([]*User, error)

func (*Gist) Identifier added in v1.6.0

func (gist *Gist) Identifier() string

func (*Gist) IncrementForkCount

func (gist *Gist) IncrementForkCount() error

func (*Gist) InitRepository

func (gist *Gist) InitRepository() error

func (*Gist) Log

func (gist *Gist) Log(skip int) ([]*git.Commit, error)

func (*Gist) NbCommits

func (gist *Gist) NbCommits() (string, error)

func (*Gist) RPC

func (gist *Gist) RPC(service string) ([]byte, error)

func (*Gist) RemoveFromIndex added in v1.6.0

func (gist *Gist) RemoveFromIndex()

func (*Gist) RemoveUserLike

func (gist *Gist) RemoveUserLike(user *User) error

func (*Gist) SetLastActiveNow

func (gist *Gist) SetLastActiveNow() error

func (*Gist) ToIndexedGist added in v1.6.0

func (gist *Gist) ToIndexedGist() (*index.Gist, error)

func (*Gist) Update

func (gist *Gist) Update() error

func (*Gist) UpdateNoTimestamps added in v1.6.0

func (gist *Gist) UpdateNoTimestamps() error

func (*Gist) UpdatePreviewAndCount

func (gist *Gist) UpdatePreviewAndCount(withTimestampUpdate bool) error

func (*Gist) UpdateServerInfo

func (gist *Gist) UpdateServerInfo() error

func (*Gist) VisibilityStr added in v1.6.0

func (gist *Gist) VisibilityStr() string

type GistDTO

type GistDTO struct {
	Title       string     `validate:"max=250" form:"title"`
	Description string     `validate:"max=1000" form:"description"`
	URL         string     `validate:"max=32,alphanumdashorempty" form:"url"`
	Private     Visibility `validate:"number,min=0,max=2" form:"private"`
	Files       []FileDTO  `validate:"min=1,dive"`
	Name        []string   `form:"name"`
	Content     []string   `form:"content"`
}

func (*GistDTO) ToExistingGist

func (dto *GistDTO) ToExistingGist(gist *Gist) *Gist

func (*GistDTO) ToGist

func (dto *GistDTO) ToGist() *Gist

type Invitation added in v1.7.0

type Invitation struct {
	ID        uint `gorm:"primaryKey"`
	Code      string
	ExpiresAt int64
	NbUsed    uint
	NbMax     uint
}

func GetAllInvitations added in v1.7.0

func GetAllInvitations() ([]*Invitation, error)

func GetInvitationByCode added in v1.7.0

func GetInvitationByCode(code string) (*Invitation, error)

func GetInvitationByID added in v1.7.0

func GetInvitationByID(id uint) (*Invitation, error)

func (*Invitation) Create added in v1.7.0

func (i *Invitation) Create() error

func (*Invitation) Delete added in v1.7.0

func (i *Invitation) Delete() error

func (*Invitation) IsExpired added in v1.7.0

func (i *Invitation) IsExpired() bool

func (*Invitation) IsMaxedOut added in v1.7.0

func (i *Invitation) IsMaxedOut() bool

func (*Invitation) IsUsable added in v1.7.0

func (i *Invitation) IsUsable() bool

func (*Invitation) Update added in v1.7.0

func (i *Invitation) Update() error

func (*Invitation) Use added in v1.7.0

func (i *Invitation) Use() error

type Like

type Like struct {
	UserID    uint `gorm:"primaryKey"`
	GistID    uint `gorm:"primaryKey"`
	CreatedAt int64
}

type MigrationVersion

type MigrationVersion struct {
	ID      uint `gorm:"primaryKey"`
	Version uint
}

type SSHKey

type SSHKey struct {
	ID         uint `gorm:"primaryKey"`
	Title      string
	Content    string
	SHA        string
	CreatedAt  int64
	LastUsedAt int64
	UserID     uint
	User       User `validate:"-" `
}

func GetSSHKeyByID

func GetSSHKeyByID(sshKeyId uint) (*SSHKey, error)

func GetSSHKeysByUserID

func GetSSHKeysByUserID(userId uint) ([]*SSHKey, error)

func SSHKeyDoesExists

func SSHKeyDoesExists(sshKeyContent string) (*SSHKey, error)

func SSHKeyExistsForUser

func SSHKeyExistsForUser(sshKey string, userId uint) (*SSHKey, error)

func (*SSHKey) BeforeCreate

func (sshKey *SSHKey) BeforeCreate(*gorm.DB) error

func (*SSHKey) Create

func (sshKey *SSHKey) Create() error

func (*SSHKey) Delete

func (sshKey *SSHKey) Delete() error

type SSHKeyDTO

type SSHKeyDTO struct {
	Title   string `form:"title" validate:"required,max=50"`
	Content string `form:"content" validate:"required"`
}

func (*SSHKeyDTO) ToSSHKey

func (dto *SSHKeyDTO) ToSSHKey() *SSHKey

type User

type User struct {
	ID        uint   `gorm:"primaryKey"`
	Username  string `gorm:"uniqueIndex"`
	Password  string
	IsAdmin   bool
	CreatedAt int64
	Email     string
	MD5Hash   string // for gravatar, if no Email is specified, the value is random
	AvatarURL string
	GithubID  string
	GitlabID  string
	GiteaID   string
	OIDCID    string `gorm:"column:oidc_id"`

	Gists   []Gist   `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:UserID"`
	SSHKeys []SSHKey `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;foreignKey:UserID"`
	Liked   []Gist   `gorm:"many2many:likes;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}

func GetAllUsers

func GetAllUsers(offset int) ([]*User, error)

func GetUserById

func GetUserById(userId uint) (*User, error)

func GetUserByProvider

func GetUserByProvider(id string, provider string) (*User, error)

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

func (*User) BeforeDelete

func (user *User) BeforeDelete(tx *gorm.DB) error

func (*User) Create

func (user *User) Create() error

func (*User) Delete

func (user *User) Delete() error

func (*User) DeleteProviderID

func (user *User) DeleteProviderID(provider string) error

func (*User) HasLiked

func (user *User) HasLiked(gist *Gist) (bool, error)

func (*User) SetAdmin

func (user *User) SetAdmin() error

func (*User) Update

func (user *User) Update() error

type UserDTO

type UserDTO struct {
	Username string `form:"username" validate:"required,max=24,alphanumdash,notreserved"`
	Password string `form:"password" validate:"required"`
}

func (*UserDTO) ToUser

func (dto *UserDTO) ToUser() *User

type Visibility added in v1.6.0

type Visibility int
const (
	PublicVisibility Visibility = iota
	UnlistedVisibility
	PrivateVisibility
)

func ParseVisibility added in v1.6.0

func ParseVisibility[T string | int](v T) (Visibility, error)

func (Visibility) Next added in v1.6.0

func (v Visibility) Next() Visibility

Jump to

Keyboard shortcuts

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