db

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDB

func InitDB(dbPath string) (*sql.DB, error)

InitDB initializes the database and creates tables if they don't exist Deprecated: Use NewDB instead

Types

type DB

type DB interface {
	SaveEntry(entry *models.Entry) error
	UpdateEntry(entry *models.Entry) error
	GetAllEntries() ([]*models.Entry, error)
	GetEntriesByCategory(category models.Category) ([]*models.Entry, error)
	GetEntryByID(id string) (*models.Entry, error)
	GetEntryCount() (int, error)
	GetEntriesFromLastWeek() ([]*models.Entry, error)
	GetEntriesSince(since time.Time) ([]*models.Entry, error)
	ExportEntries(filePath string) error
	ExportEntriesSince(filePath string, since time.Time) error
	ImportEntries(filePath string) (int, error)
	Close() error
}

DB is the interface for database operations

func GetDB

func GetDB(dbPath string) (DB, error)

GetDB returns a global singleton instance of the database This is maintained for backward compatibility but should be avoided in favor of dependency injection with NewDB

func NewDB

func NewDB(dbPath string) (DB, error)

NewDB creates a new DB instance with dependency injection

type SQLiteDB

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

SQLiteDB implements the DB interface with SQLite

func (*SQLiteDB) Close

func (s *SQLiteDB) Close() error

Close closes the database connection

func (*SQLiteDB) ExportEntries added in v0.2.2

func (s *SQLiteDB) ExportEntries(filePath string) error

ExportEntries exports all entries from the database to a JSON file Each entry is written as a separate JSON object on its own line (JSON Lines format)

func (*SQLiteDB) ExportEntriesSince added in v0.2.3

func (s *SQLiteDB) ExportEntriesSince(filePath string, since time.Time) error

ExportEntriesSince exports entries from the database created after the specified time to a JSON file Each entry is written as a separate JSON object on its own line (JSON Lines format)

func (*SQLiteDB) GetAllEntries

func (s *SQLiteDB) GetAllEntries() ([]*models.Entry, error)

GetAllEntries retrieves all entries from the database

func (*SQLiteDB) GetEntriesByCategory

func (s *SQLiteDB) GetEntriesByCategory(category models.Category) ([]*models.Entry, error)

GetEntriesByCategory retrieves entries by category

func (*SQLiteDB) GetEntriesFromLastWeek

func (s *SQLiteDB) GetEntriesFromLastWeek() ([]*models.Entry, error)

GetEntriesFromLastWeek retrieves entries from the past 7 days

func (*SQLiteDB) GetEntriesSince added in v0.2.3

func (s *SQLiteDB) GetEntriesSince(since time.Time) ([]*models.Entry, error)

GetEntriesSince retrieves entries created after the specified time

func (*SQLiteDB) GetEntryByID

func (s *SQLiteDB) GetEntryByID(id string) (*models.Entry, error)

GetEntryByID retrieves an entry by ID

func (*SQLiteDB) GetEntryCount

func (s *SQLiteDB) GetEntryCount() (int, error)

GetEntryCount returns the total number of entries

func (*SQLiteDB) ImportEntries added in v0.2.3

func (s *SQLiteDB) ImportEntries(filePath string) (int, error)

ImportEntries imports entries from a JSON file into the database

func (*SQLiteDB) SaveEntry

func (s *SQLiteDB) SaveEntry(entry *models.Entry) error

SaveEntry saves an entry to the database

func (*SQLiteDB) UpdateEntry

func (s *SQLiteDB) UpdateEntry(entry *models.Entry) error

UpdateEntry updates an existing entry in the database

Jump to

Keyboard shortcuts

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