sqlite

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqlite provides a reference implementation of a Bernard datastore. Other SQL implementations should ideally borrow from this code as the SQL should be compatible with other drivers as well.

Index

Constants

View Source
const Schema string = `` /* 719-byte string literal not displayed */

Schema of the sqlite database

Variables

View Source
var ErrInvalidStatement = fmt.Errorf("invalid statement: %w", ds.ErrDatabase)

ErrInvalidStatement occurs when the SQL statement is not compatible with the underlying driver or when the database is not initialised with tables yet.

View Source
var ErrTransaction = fmt.Errorf("transaction: %w", ds.ErrDatabase)

ErrTransaction can have values begin or commit, and indicates an error when beginning or commiting a transaction

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	DB *sql.DB
}

Datastore holds our SQLite3 database connection and implements the Bernard Datastore interface.

func FromDB added in v0.3.3

func FromDB(db *sql.DB) (*Datastore, error)

FromDB returns a Bernard Datastore with the given SQLite3 backend.

func New

func New(path string) (*Datastore, error)

New returns a Bernard Datastore with a SQLite3 backend.

func (*Datastore) FullSync

func (store *Datastore) FullSync(drive ds.Drive, folders []ds.Folder, files []ds.File) (err error)

FullSync synchronises the provided Drive state to the datastore.

func (*Datastore) NewDifferencesHook

func (store *Datastore) NewDifferencesHook() (bernard.Hook, *Difference)

NewDifferencesHook creates a Hook which checks which files and folders have been added, changed or removed.

Like all hooks, the corresponding output struct is only updated when the hook is executed.

func (*Datastore) PageToken

func (store *Datastore) PageToken(driveID string) (string, error)

PageToken retrieves the pageToken the datastore currently reflects.

func (*Datastore) PartialSync

func (store *Datastore) PartialSync(drive ds.Drive, changedFolders []ds.Folder, changedFiles []ds.File, removedIDs []string) error

PartialSync synchronises the provided changes to the datastore.

1. Update the pageToken and (if applicable) the name of the Shared Drive.

2. Process changed folders with UPSERT.

3. Process changed folders with UPSERT.

4. Remove any items of which the IDs match with the removedIDs slice.

type Difference

type Difference struct {
	AddedFiles   []ds.File
	ChangedFiles []FileDifference
	RemovedFiles []ds.File

	AddedFolders   []ds.Folder
	ChangedFolders []FolderDifference
	RemovedFolders []ds.Folder
}

The Difference contains all added, changes and removed files and folders between two states.

type FileDifference

type FileDifference struct {
	Old ds.File
	New ds.File
}

type FolderDifference

type FolderDifference struct {
	Old ds.Folder
	New ds.Folder
}

Jump to

Keyboard shortcuts

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