localstore

package
v0.0.0-...-f9b5ad8 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFileExists

func CheckFileExists(file string) bool

CheckFileExists is a reuseable function which returns true if a file exists at a known location

func InitDB

func InitDB(i Sqlstore) error

InitDB create the datastore file and run CreateDB

Types

type Config

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

Config is the SQL DB Config object

func NewLocalStore

func NewLocalStore(location, table string, include, exclude []string) *Config

NewLocalStore will create stuff...

func (*Config) Check

func (c *Config) Check(newRecords bool, table string, db *sql.DB) ([]StoredFileRecord, error)

Check will compare the input table to the backup location table. It always returns files that have changed their filename, filepath, etag or sha1sum. Use newRecords==true looks for new files. Use newRecords==false to look for missing/deleted files. Program needs to go through the results set to understand if file is missing/new or changed. Unoptimised for large record sets according to https://stackoverflow.com/questions/45069655/is-there-a-faster-way-to-compare-two-sqlite3-tables-in-python

func (*Config) CreateDB

func (c *Config) CreateDB(db *sql.DB) error

CreateDB will bootstrap the datastore file with the schema

func (*Config) CreateFile

func (c *Config) CreateFile(file string) error

CreateFile will create a blank file to disk

func (*Config) CreateTempTable

func (c *Config) CreateTempTable(db *sql.DB) (string, error)

CreateTempTable will create and return a temporary table to store records

func (*Config) DropTempTable

func (c *Config) DropTempTable(table string, db *sql.DB) error

DropTempTable will drop the above temp table

func (*Config) GetSqliteDB

func (c *Config) GetSqliteDB(database string) (*sql.DB, error)

GetSqliteDB returns the sql.DB object

func (*Config) ReadFileRecord

func (c *Config) ReadFileRecord(record FileRecord, table string, db *sql.DB) ([]StoredFileRecord, error)

ReadFileRecord will return a set of results based on the input parameters

func (*Config) ReadMetadata

func (c *Config) ReadMetadata(db *sql.DB) (Metadata, error)

ReadMetadata returns the metadata from the table

func (*Config) UpdateMetadata

func (c *Config) UpdateMetadata(db *sql.DB) error

UpdateMetadata will simply update the metadata table. Should only be called after write to table.

func (*Config) WriteFileRecord

func (c *Config) WriteFileRecord(record FileRecord, db *sql.DB) error

WriteFileRecord will write the file info to the data table

func (*Config) WriteFileRecordTempTable

func (c *Config) WriteFileRecordTempTable(record FileRecord, db *sql.DB) error

WriteFileRecordTempTable will write the file info to the data table

type FileRecord

type FileRecord struct {
	Filename string
	FilePath string
	Sha1sum  string
	Etag     string
}

FileRecord Type is what we want to update/modify

type Metadata

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

Metadata stores the returned metadata from the sqlstore

func (*Metadata) GetExclude

func (m *Metadata) GetExclude() []string

GetExclude will fetch the excluded regex lookup

func (*Metadata) GetInclude

func (m *Metadata) GetInclude() []string

GetInclude will fetch the include regex lookup

func (*Metadata) GetLastModified

func (m *Metadata) GetLastModified() string

GetLastModified will fetch the timestamp of the last modified datetime

func (*Metadata) GetLocation

func (m *Metadata) GetLocation() string

GetLocation will return the internal struct location

type Sqlstore

type Sqlstore interface {
	CreateFile(string) error
	CreateDB(db *sql.DB) error
	GetSqliteDB(string) (*sql.DB, error)
	UpdateMetadata(db *sql.DB) error
	// contains filtered or unexported methods
}

Sqlstore does stuff

type StoredFileRecord

type StoredFileRecord struct {
	FileRecord
	ID        int
	Timestamp string
}

StoredFileRecord is the FileRecord which is stored in the database

func AppendFileRecordIfMissing

func AppendFileRecordIfMissing(slice []StoredFileRecord, fr StoredFileRecord) []StoredFileRecord

AppendFileRecordIfMissing simply adds to the array if not found

Jump to

Keyboard shortcuts

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