database

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OptFunc

type OptFunc func(*SQLite3) *SQLite3

func WithLogger

func WithLogger(logger *slog.Logger) OptFunc

WithLogger sets custom logger.

type Record

type Record struct {
	ID           int64
	Link         string
	Name         string
	CategoryName string
}

type SQLite3

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

func NewSQLite3

func NewSQLite3(opts ...OptFunc) *SQLite3

func (*SQLite3) Close

func (s *SQLite3) Close() error

Close closes the database. It is important to call before terminating the application.

func (*SQLite3) DeleteByID

func (s *SQLite3) DeleteByID(ctx context.Context, id int64) (bool, error)

DeleteByID deletes the given id from the links table.

func (*SQLite3) List

func (s *SQLite3) List(ctx context.Context) ([]Record, error)

List fetches the Record and returns slice of Record.

func (*SQLite3) Open

func (s *SQLite3) Open(ctx context.Context, filename string) error

Open opens database connections.

func (*SQLite3) Save

func (s *SQLite3) Save(ctx context.Context, link string, name string, categoryName string) (int64, error)

Save inserts the given link, name, and categories to links and categories tables.

type Storage

type Storage interface {
	// Save saves the link to database.
	Save(ctx context.Context, link string, name string, categoryName string) (int64, error)

	// List returns the links in map. The key is number and the value is the link.
	List(ctx context.Context) ([]Record, error)

	// DeleteByID deletes the links by given IDs.
	DeleteByID(ctx context.Context, id int64) (bool, error)

	Close() error
}

Jump to

Keyboard shortcuts

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