db

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EntryMutations

type EntryMutations []VersionedEntry

EntryMutations contains the details of the mutation of an entry. There will be only one entry in the case of a Creation or a Deletion. There will be 2 entries in the case of an Update or a Modification, in which case the first entry will be the "from" state and the second will be the "to" state.

type FSDriver

type FSDriver string
const (
	FSDriverPCloud FSDriver = "pCloud"
	FSDriverLocal  FSDriver = "Local"
)

type FSEntry

type FSEntry struct {
	FSName         FSName
	DeviceID       string // for cloud, this could be used to distinguish multiple accounts on the same cloud provider
	EntryID        uint64
	IsFolder       bool
	Path           string
	Name           string
	ParentFolderID uint64
	Created        time.Time
	Modified       time.Time
	Size           uint64
	Hash           string
}

FSEntry is a set of details about an entry (folder or file) in the file system.

type FSInfo

type FSInfo struct {
	FSName    FSName
	FSDriver  FSDriver
	FSRoot    string
	FSChanged bool
}

type FSMutation

type FSMutation struct {
	Type    MutationType
	Details EntryMutations
}

FSMutation contains a file system mutation: type and details.

type FSMutations

type FSMutations []FSMutation

type FSName

type FSName string

FSName is a descriptive name for the tracked file system.

type Migrator

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

func NewMigrator

func NewMigrator(db *sql.DB) *Migrator

NewMigrator creates a new initialised Migrator struct.

func (*Migrator) MigrateUp

func (m *Migrator) MigrateUp(ctx context.Context) (err error)

type MutationType

type MutationType string

MutationType describes the type of mutation of a file system.

const (
	// MutationTypeDeleted means a deletion on the file system.
	MutationTypeDeleted MutationType = "deleted"
	// MutationTypeCreated means a creation on the file system.
	MutationTypeCreated MutationType = "created"
	// MutationTypeModified means a file content modification on the file system.
	MutationTypeModified MutationType = "modified"
	// MutationTypeMoved means a file move on the file system.
	MutationTypeMoved MutationType = "moved"
)

type Options

type Options func(*config)

Options defines the signature of a functional parameter for AddNewFileSystemEntries.

func WithEntriesChannelSize

func WithEntriesChannelSize(n int) Options

WithEntriesChannelSize is a functional parameter that allows to choose the size of the entries channel used by AddNewFileSystemEntries.

type PairName

type PairName string

type SQLite3

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

SQLite3 is a sqlite3 database store.

func NewSQLite3

func NewSQLite3(ctx context.Context, dbPath string) (*SQLite3, error)

NewSQLite3 creates a new initialised SQLite3.

func (*SQLite3) AddNewFileSystemEntries

func (s *SQLite3) AddNewFileSystemEntries(ctx context.Context, opts ...Options) (chan<- FSEntry, <-chan error)

AddNewFileSystemEntries adds a new file system entry. It returns two channels: - the first is used to supply data to this method - the second is a channel of error type should this function encounter an error. Refer to tests and main code for example uses.

func (*SQLite3) Close

func (s *SQLite3) Close() error

Close closes the connection to sqlite3.

func (*SQLite3) DeleteVersionNew

func (s *SQLite3) DeleteVersionNew(ctx context.Context, fsName FSName) error

DeleteVersionNew removes "new" file system entries for the specified file system. This would be performed with a view to load a new "VersionNew" set, in replacement.

func (*SQLite3) FindSyncPeers

func (s *SQLite3) FindSyncPeers(ctx context.Context, fsName FSName) ([]FSName, error)

func (*SQLite3) GetFileSystemInfo

func (s *SQLite3) GetFileSystemInfo(ctx context.Context, fsName FSName) (*FSInfo, error)

GetFileSystemInfo returns high level information about the file system fsName. It will return an error (no rows found) if it cannot find the status row.

func (*SQLite3) GetFileSystemMutations

func (s *SQLite3) GetFileSystemMutations(ctx context.Context, fsName FSName) (FSMutations, error)

GetFileSystemMutations returns a slice of mutations for the specified file system. It should be noted that up to two rows may be created: one for each version: previous and new.

func (*SQLite3) GetLatestFileSystemEntries

func (s *SQLite3) GetLatestFileSystemEntries(ctx context.Context, fsName FSName) ([]FSEntry, error)

GetLatestFileSystemEntries get the latest (i.e. version "New") file system entries for the specified file system type.

func (*SQLite3) GetPCloudVsLocalMutations

func (s *SQLite3) GetPCloudVsLocalMutations(ctx context.Context) (FSMutations, error)

GetPCloudVsLocalMutations returns a slice of mutations that exist between the pCloud file system and the local file system.

func (*SQLite3) GetPreviousFileSystemEntries

func (s *SQLite3) GetPreviousFileSystemEntries(ctx context.Context, fsName FSName) ([]FSEntry, error)

GetPreviousFileSystemEntries get the previous (i.e. version "Previous") file system entries for the specified file system type.

func (*SQLite3) GetSyncDetails

func (s *SQLite3) GetSyncDetails(ctx context.Context, fsName FSName) (FSDriver, string, error)

GetSyncDetails returns the driver for the specified file system name and the root path.

func (*SQLite3) IsFileSystemEmpty

func (s *SQLite3) IsFileSystemEmpty(ctx context.Context, fsName FSName) (bool, error)

IsFileSystemEmpty returns true if no entry data exists at all in the database for `fsName`, otherwise it returns false.

func (*SQLite3) MarkFileSystemAsChanged

func (s *SQLite3) MarkFileSystemAsChanged(ctx context.Context, fsName FSName) error

MarkFileSystemAsChanged marks the status of the file system as "changed". This also triggers the internal refresh of all staging tables.

func (*SQLite3) MarkSyncAsChanged

func (s *SQLite3) MarkSyncAsChanged(ctx context.Context, fsName FSName) error

MarkSyncAsChanged marks the status of the sync as "changed". This also triggers the internal refresh of all staging tables.

func (*SQLite3) MarkSyncComplete

func (s *SQLite3) MarkSyncComplete(ctx context.Context, fsName FSName) error

MarkSyncComplete marks the status of the sync as "complete". TODO: it may be that the staging table should be cleared down, although not essential because that is properly taken care of by other methods that change the state of table "filesystem".

func (*SQLite3) MarkSyncInProgress

func (s *SQLite3) MarkSyncInProgress(ctx context.Context, fsName FSName) error

MarkSyncInProgress marks the status of the sync as "in progress".

func (*SQLite3) RotateFileSystemVersions

func (s *SQLite3) RotateFileSystemVersions(ctx context.Context, fsName FSName) error

RotateFileSystemVersions clears the "previous" file system entries for the specified file system and marks the "new" file system entries as "previous".

type SyncPair

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

type SyncStatus

type SyncStatus string

SyncStatus defines the status of the sync. It is used to prevent refreshing data in the filesystem table when it has not yet been completely sync'ed. In particular, VersionPrevious should not be replaced with new data until the sync has completed or some delta changes between "previous" and "new" will be lost and non-replicated. This should not be confused with the sync that takes place across filesystems (such as cloud vs local) which only involves VersionNew of each filesystems. It is always safe to update VersionNew (but not VersionPrevious until processed).

const (
	// SyncStatusComplete indicates VersionPrevious has been completely sync'ed and can now be
	// replaced with newer data.
	SyncStatusComplete SyncStatus = "Complete"

	// SyncStatusRequired indicates VersionPrevious has just been refreshed and requires
	// sync'ing against VersionNew.
	SyncStatusRequired SyncStatus = "Required"

	// SyncStatusInProgress indicates that the sync between VersionPrevious and VersionNew is in
	// progress.
	SyncStatusInProgress SyncStatus = "In progress"
)

type Version

type Version string

Version is used to distinguish the two entry-sets of file system data in the database.

const (
	// VersionPrevious is the previous version of file system entries in the database.
	VersionPrevious Version = "Previous"
	// VersionNew is the newer version of file system entries in the database.
	VersionNew Version = "New"
)

type VersionedEntry

type VersionedEntry struct {
	Version
	FSEntry
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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