sqlite

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

This is the implementation of the store.URLDataStore interface for sqlite.

Use New() to make a new sqlite storage instance.

  • You *must* call Open()
  • The DB will be closed when the context passed to Open() is cancelled.
  • Concurrent usage OK
  • In-Memory DBs are supported
  • The DB will be created if it doesn't exist

Index

Constants

View Source
const (
	EnvDBPath                       = "SCRAPE_DB"
	DefaultBusyTimeout              = 5 * time.Second
	DefaultQueryTimeout             = 30 * time.Second
	JournalModeWAL      JournalMode = "WAL"
	JournalModeMemory   JournalMode = "MEMORY"
	JournalModeOff      JournalMode = "OFF"
	BigCacheSize                    = 20000
	NormalCacheSize                 = 2000 // This is actually the sqlite default
	SyncOff             SyncMode    = "OFF"
	SyncNormal          SyncMode    = "NORMAL"
	AccessModeRWC       AccessMode  = "rwc"
	AccessModeMemory    AccessMode  = "memory"
)
View Source
const (
	InMemoryDBName = ":memory:"
)

Variables

View Source
var (
	DefaultDatabase   = "scrape_data/scrape.db"
	ErrDatabaseExists = errors.New("database already exists")
	ErrIsInMemory     = errors.New("file path is in-memory DB (':memory:')")
)

Functions

func Defaults

func Defaults() option

Defaults always get applied in the New() function

func Factory

func Factory(options ...option) store.Factory

Returns the factory function that can be used to instantiate a sqlite store in the cases where either creation should be delayed or where the caller may want to instantiate multiple stores with the same configuration.

func File

func File(filename string) option

func InMemoryDB

func InMemoryDB() option

func WithFileOrEnv

func WithFileOrEnv(filename string) option

func WithQueryTimeout

func WithQueryTimeout(timeout time.Duration) option

Types

type AccessMode

type AccessMode string

type FilesystemStats

type FilesystemStats struct {
	Path    string `json:"path"`
	TotalMB uint   `json:"total_mb"`
	UsedMB  uint   `json:"used_mb"`
	FreeMB  uint   `json:"free_mb"`
	AvailMB uint   `json:"avail_mb"`
}

type JournalMode

type JournalMode string

type Stats

type Stats struct {
	SqliteVersion string           `json:"sqlite_version"`
	PageCount     int              `json:"page_count"`
	PageSize      int              `json:"page_size"`
	UnusedPages   int              `json:"unused_pages"`
	MaxPageCount  int              `json:"max_page_count"`
	Filesystem    *FilesystemStats `json:"fs,omitempty"`
	// contains filtered or unexported fields
}

func (*Stats) DatabaseSizeMB

func (s *Stats) DatabaseSizeMB() int

type Store

type Store struct {
	*storage.SQLStorage
	// contains filtered or unexported fields
}

Store is the sqlite implementation of the store.URLDataStore interface. It relies on storage.SQLStorage for most of the actual database operations, and mainly handles configuration and initialization.

func New

func New(options ...option) (*Store, error)

func (*Store) Create

func (s *Store) Create() error

When this is called, the path to the database must already exist.

func (*Store) Maintain

func (s *Store) Maintain() error

func (*Store) Open

func (s *Store) Open(ctx context.Context) error

Opens the database, creating it if it doesn't exist. The passed contexts will be used for query preparation, and to close the database when the context is cancelled.

func (*Store) Stats

func (s *Store) Stats() (any, error)

Implements the store.Observable interface. Return value intended to be included in JSON outputs. For introspection of the results, type assert to *sqlite.Stats.

type SyncMode

type SyncMode string

Jump to

Keyboard shortcuts

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