db

package
v0.0.0-...-84f50f4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SessionLength           = 32
	CSRFTokenLength         = 32
	SessionDuration         = 90 * 24 * time.Hour
	SessionRotationInterval = 30 * time.Minute
)

Functions

This section is empty.

Types

type DB

type DB struct {
	Users    *Users
	Sessions *Sessions
	Links    *Links
	Visits   *Visits
	// contains filtered or unexported fields
}

func StartDB

func StartDB(context *foundation.Context) (*DB, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) SetSQLDB

func (db *DB) SetSQLDB(sqlDB *sql.DB)
type Links struct {
	// contains filtered or unexported fields
}

func (*Links) All

func (l *Links) All(ctx context.Context) ([]*foundation.Link, error)

func (*Links) AllWithVisitCounts

func (l *Links) AllWithVisitCounts(ctx context.Context) ([]*foundation.Link, error)
func (l *Links) ByShortLink(ctx context.Context, shortLink string) (*foundation.Link, error)

func (*Links) Delete

func (l *Links) Delete(ctx context.Context, shortLink string) error

func (*Links) Insert

func (l *Links) Insert(ctx context.Context, link *foundation.Link) error

func (*Links) Update

func (l *Links) Update(ctx context.Context, link *foundation.Link) error

type Sessions

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

func (*Sessions) ByID

func (s *Sessions) ByID(ctx context.Context, sessionID string) (*foundation.Session, error)

func (*Sessions) Delete

func (s *Sessions) Delete(ctx context.Context, sessionID string) error

func (*Sessions) InsertAnonymousSession

func (s *Sessions) InsertAnonymousSession(ctx context.Context) (*foundation.Session, error)

InsertAnonymousSession creates a new anonymous session (no user ID)

func (*Sessions) InsertUserSession

func (s *Sessions) InsertUserSession(ctx context.Context, userID int64) (*foundation.Session, error)

InsertUserSession creates a new session for a user

func (*Sessions) RotateSessionIfNeeded

func (s *Sessions) RotateSessionIfNeeded(ctx context.Context, sessionID string) (*foundation.Session, error)

type Users

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

func (*Users) All

func (u *Users) All(ctx context.Context) ([]*foundation.User, error)

func (*Users) ByID

func (u *Users) ByID(ctx context.Context, id int64) (*foundation.User, error)

func (*Users) ByUsername

func (u *Users) ByUsername(ctx context.Context, username string) (*foundation.User, error)

func (*Users) Delete

func (u *Users) Delete(ctx context.Context, userID int64) error

func (*Users) ExistsByUsername

func (u *Users) ExistsByUsername(ctx context.Context, username string) (bool, error)

func (*Users) Insert

func (u *Users) Insert(ctx context.Context, user *foundation.User) error

func (*Users) Update

func (u *Users) Update(ctx context.Context, user *foundation.User) error

type Visits

type Visits struct {
	// contains filtered or unexported fields
}
func (v *Visits) CountByLink(ctx context.Context, shortLink string) (int64, error)

func (*Visits) Insert

func (v *Visits) Insert(ctx context.Context, visit *foundation.LinkVisit) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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