database

package
v0.0.0-...-cbd9749 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Database Connection
	ErrorDatabaseDriverInvalid = errors.New("given database driver is invalid")
	ErrorDatabaseSourceInvalid = errors.New("given database source is invalid")
	ErrorConnectionFailed      = errors.New("can not connect to database")
	// Migrations
	ErrorMigrationFailed = errors.New("failed to migrate database")
	// Query operations
	ErrorRecordNotFound  = errors.New("record with given query not found")
	ErrorOperationFailed = errors.New("operation failed")
	// context
	ErrorOperationCanceled = errors.New("operation canceled")
	// Validations
	ErrorInvalidShortened = errors.New("invalid shortened")
)

Functions

This section is empty.

Types

type Database

type Database struct {
	ShortenedRepo ShortenedRepo
	// contains filtered or unexported fields
}

func New

func New(driver string, source string, config *gorm.Config) (*Database, error)

type Shortened

type Shortened struct {
	ID          string `gorm:"type:uuid;primary_key;"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
	DeletedAt   gorm.DeletedAt `gorm:"index"`
	OriginalUrl string         `gorm:"not null;size:128;;" json:"original_url"`
	ShortUrl    string         `gorm:"not null;size:128;unique;;" json:"short_url"`
}

func (Shortened) String

func (s Shortened) String() string

String method, returns Shortened<ID:ShortUrl:OriginalUrl:CreatedAt>

type ShortenedRepo

type ShortenedRepo interface {
	Find(ctx context.Context, shortUrl string) (Shortened, error)
	FindByOriginal(ctx context.Context, url string) (Shortened, error)
	Add(ctx context.Context, shortened Shortened) error
	Delete(ctx context.Context, shortened Shortened) error
}

type SqlShortenedRepo

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

func NewSqlShortenedRepo

func NewSqlShortenedRepo(db *gorm.DB) *SqlShortenedRepo

func (SqlShortenedRepo) Add

func (repo SqlShortenedRepo) Add(ctx context.Context, shortened Shortened) error

func (SqlShortenedRepo) Delete

func (repo SqlShortenedRepo) Delete(ctx context.Context, shortened Shortened) error

func (SqlShortenedRepo) Find

func (repo SqlShortenedRepo) Find(ctx context.Context, shortUrl string) (Shortened, error)

func (SqlShortenedRepo) FindByOriginal

func (repo SqlShortenedRepo) FindByOriginal(ctx context.Context, url string) (Shortened, error)

Jump to

Keyboard shortcuts

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