bunstorage

package
v1.8.17 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BunStorage

type BunStorage struct {

	// StartHooks are ran after the database is connected and the tables are created.
	StartHooks []func(ctx context.Context, db *bun.DB) error
	// StopHooks are ran before the database is closed.
	StopHook []func(ctx context.Context, db *bun.DB) error
	// contains filtered or unexported fields
}

func NewBunStorage

func NewBunStorage(cfg *config.Config, db *bun.DB) *BunStorage

func (*BunStorage) ChangeTokenName

func (s *BunStorage) ChangeTokenName(ctx context.Context, token *models.Token, name string) (*models.Token, error)

func (*BunStorage) CreateShort

func (s *BunStorage) CreateShort(ctx context.Context, short *models.Short) (*models.Short, error)

func (*BunStorage) CreateShortLog

func (s *BunStorage) CreateShortLog(ctx context.Context, shortLog *models.ShortLog) error

func (*BunStorage) CreateToken

func (s *BunStorage) CreateToken(ctx context.Context, token *models.Token) (*models.Token, error)

func (*BunStorage) CreateUser

func (s *BunStorage) CreateUser(ctx context.Context, user *models.User) (*models.User, error)

func (*BunStorage) DeleteShort

func (s *BunStorage) DeleteShort(ctx context.Context, short *models.Short) error

func (*BunStorage) DeleteToken

func (s *BunStorage) DeleteToken(ctx context.Context, token *models.Token) error

func (*BunStorage) DeleteUser

func (s *BunStorage) DeleteUser(ctx context.Context, user *models.User) error

func (*BunStorage) FindShort

func (s *BunStorage) FindShort(ctx context.Context, name string) (*models.Short, error)

func (*BunStorage) FindShortByID

func (s *BunStorage) FindShortByID(ctx context.Context, id string) (*models.Short, error)

func (*BunStorage) FindToken

func (s *BunStorage) FindToken(ctx context.Context, value string) (*models.Token, error)

func (*BunStorage) FindTokenByID

func (s *BunStorage) FindTokenByID(ctx context.Context, id string) (*models.Token, error)

func (*BunStorage) FindUser

func (s *BunStorage) FindUser(ctx context.Context, username string) (*models.User, error)

func (*BunStorage) FindUserByID

func (s *BunStorage) FindUserByID(ctx context.Context, id string) (*models.User, error)

func (*BunStorage) ListShortLogs

func (s *BunStorage) ListShortLogs(ctx context.Context, short *models.Short) ([]*models.ShortLog, error)

func (*BunStorage) ListShorts

func (s *BunStorage) ListShorts(ctx context.Context, user *models.User) ([]*models.Short, error)

func (*BunStorage) ListTokens

func (s *BunStorage) ListTokens(ctx context.Context, user *models.User) ([]*models.Token, error)

func (*BunStorage) Ping

func (s *BunStorage) Ping(ctx context.Context) error

func (*BunStorage) RegisterStartHook

func (s *BunStorage) RegisterStartHook(hook func(ctx context.Context, db *bun.DB) error)

RegisterStartHook registers a hook to be ran after the database is connected and the tables are created.

func (*BunStorage) RegisterStopHook

func (s *BunStorage) RegisterStopHook(hook func(ctx context.Context, db *bun.DB) error)

RegisterStopHook registers a hook to be ran before the database is closed.

func (*BunStorage) Start

func (s *BunStorage) Start(ctx context.Context) error

func (*BunStorage) Stop

func (s *BunStorage) Stop(ctx context.Context) error

type ShortLogModel

type ShortLogModel struct {
	bun.BaseModel `bun:"table:short_logs,alias:sl"`

	// ID is the primary key
	ID string `bun:",pk,unique,notnull" json:"id"`
	// IPAddress is the IP address of the client that accessed the short
	IPAddress string `bun:"" json:"ipAddress"`
	// UserAgent is the User-Agent of the client that accessed the short
	UserAgent string `bun:"" json:"userAgent"`
	// Referer is the referer of the client that accessed the short
	Referer string `bun:"" json:"referer"`
	// CreatedAt is when the short was accessed
	CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`

	// ShortID is the ID of the short that was accessed
	ShortID string `bun:",notnull" json:"-"`
}

type ShortModel

type ShortModel struct {
	bun.BaseModel `bun:"table:shorts,alias:s" json:"-"`

	ID string `bun:",pk,unique,notnull" json:"id"`
	// Name is the short's name, which is also the path to access it
	Name string `bun:",unique,notnull" json:"name"`
	// URL is the URL that the short will redirect to
	URL string `bun:",notnull" json:"url"`
	// Deleted is whether the short is soft-deleted or not
	Deleted bool `bun:",notnull,default:false" json:"-"`
	// CreatedAt is when the short was created (initialized by the storage)
	CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
	// DeletedAt is when the short was deleted
	DeletedAt time.Time `bun:"" json:"-"`

	// UserID is the ID of the user that created the short
	// This can be null if the short was deleted
	UserID *string `json:"-"`
}

type TokenModel

type TokenModel struct {
	bun.BaseModel `bun:"table:tokens,alias:t"`

	// ID is the primary key
	ID string `bun:",pk,unique,notnull" json:"id"`
	// Name is the user-friendly name of the token
	Name string `bun:",notnull" json:"name"`
	// Value is the actual token
	Value string `bun:",unique,notnull" json:"value"`
	// CreatedAt is when the token was created (initialized by the storage)
	CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`

	// UserID is the ID of the user that created the token
	UserID *string `bun:",notnull" json:"-"`
}

type UserModel

type UserModel struct {
	bun.BaseModel `bun:"table:users,alias:u"`

	// ID is the primary key
	ID string `bun:",pk,unique,notnull" json:"id"`
	// Username is the user's username
	Username string `bun:",unique,notnull" json:"username"`
	// Password is the user's password
	Password string `bun:",notnull" json:"-"`
	// CreatedAt is when the user was created (initialized by the storage)
	CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"`
}

Jump to

Keyboard shortcuts

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