db

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, dialect string, dsn string, config *gorm.Config) (db *gorm.DB, err error)

New creates a new database connection

func NewLogger

func NewLogger(level string) *dlogger

func NewMySQL

func NewMySQL(dsn string, config *gorm.Config) (*gorm.DB, error)

NewMySQL Creates a new MySQL Database Connection

func NewSQLite

func NewSQLite(file string, config *gorm.Config) (*gorm.DB, error)

NewSQLite --

Types

type Group

type Group struct {
	ID          int64         `gorm:"primaryKey;autoIncrement:false" json:"id"`
	Name        string        `json:"name"`
	Active      bool          `json:"active"`
	CreatedAt   *time.Time    `json:"created_at"`
	UpdatedAt   *time.Time    `json:"updated_at"`
	Users       []*User       `gorm:"many2many:user_groups" json:"users,omitempty"`
	Permissions []*Permission `gorm:"foreignKey:EntityID" json:"permissions,omitempty"`
}

Group --

func (*Group) BeforeCreate

func (g *Group) BeforeCreate(tx *gorm.DB) error

BeforeCreate --

type PKI

type PKI struct {
	ID        int64 `gorm:"primaryKey;autoIncrement:false" json:"id"`
	Type      string
	Bits      int
	Private   string
	Public    string
	X509      string
	NotBefore *time.Time
	ExpiresAt *time.Time
	Active    bool
	CreatedAt *time.Time `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`
}

func (*PKI) AfterCreate

func (p *PKI) AfterCreate(tx *gorm.DB) (err error)

func (*PKI) AfterUpdate

func (p *PKI) AfterUpdate(tx *gorm.DB) (err error)

type Permission

type Permission struct {
	ID        int64            `gorm:"primaryKey;autoIncrement:false" json:"id"`
	Type      PermissionType   `gorm:"index:idx_permissions_unique,unique" json:"type"`
	Class     string           `gorm:"index:idx_permissions_unique,unique" json:"class,omitempty"`
	Name      string           `gorm:"index:idx_permissions_unique,unique" json:"name"`
	Action    PermissionAction `json:"action"`
	EntityID  int64            `json:"-"`
	User      *User            `gorm:"foreignKey:EntityID" json:"user,omitempty"`
	Group     *Group           `gorm:"foreignKey:EntityID" json:"group,omitempty"`
	CreatedAt *time.Time       `json:"created_at"`
	UpdatedAt *time.Time       `json:"updated_at"`
}

func (*Permission) BeforeCreate

func (p *Permission) BeforeCreate(tx *gorm.DB) error

type PermissionAction

type PermissionAction string
const (
	Pull  PermissionAction = "pull"
	Push  PermissionAction = "push"
	Admin PermissionAction = "admin"
)

type PermissionType

type PermissionType string
const (
	Registry   PermissionType = "registry"
	Catalog    PermissionType = "catalog"
	Namespace  PermissionType = "namespace"
	Repository PermissionType = "repository"
)

type Token

type Token struct {
	ID           int64 `gorm:"primaryKey;autoIncrement:false" json:"id"`
	AccessToken  string
	RefreshToken string
	ExpiresIn    int
	IssuedAt     *time.Time
	ExpiresAt    *time.Time
	UserID       int64
	CreatedAt    *time.Time `json:"created_at"`
	UpdatedAt    *time.Time `json:"updated_at"`
}

type User

type User struct {
	ID          int64         `gorm:"primaryKey;autoIncrement:false" json:"id"`
	Name        string        `json:"name"`
	Username    string        `gorm:"uniqueIndex,size:255"`
	Password    string        `json:"-"`
	Admin       bool          `json:"admin"`
	Active      bool          `json:"active"`
	CreatedAt   *time.Time    `json:"created_at"`
	UpdatedAt   *time.Time    `json:"updated_at"`
	Groups      []*Group      `gorm:"many2many:user_groups" json:"groups,omitempty"`
	Permissions []*Permission `gorm:"foreignKey:EntityID" json:"permissions,omitempty"`
	Tokens      []*Token      `gorm:"foreignKey:UserID" json:"users,omitempty"`
}

User --

func (*User) BeforeCreate

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

BeforeCreate --

func (*User) BeforeUpdate

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

Jump to

Keyboard shortcuts

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