sqlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectionDAO added in v0.2.0

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

CollectionDAO persists collections (e.g. tags) in the SQLite database.

func NewCollectionDAO added in v0.2.0

func NewCollectionDAO(tx Transaction, logger util.Logger) *CollectionDAO

NewCollectionDAO creates a new instance of a DAO working on the given database transaction.

func (*CollectionDAO) Associate added in v0.2.0

func (d *CollectionDAO) Associate(noteId core.NoteId, collectionId core.CollectionId) (core.NoteCollectionId, error)

Associate creates a new association between a note and a collection, if it does not already exist.

func (*CollectionDAO) FindOrCreate added in v0.2.0

func (d *CollectionDAO) FindOrCreate(kind note.CollectionKind, name string) (core.CollectionId, error)

FindOrCreate returns the ID of the collection with given kind and name. Creates the collection if it does not already exist.

func (*CollectionDAO) RemoveAssociations added in v0.2.0

func (d *CollectionDAO) RemoveAssociations(noteId core.NoteId) error

RemoveAssociations deletes all associations with the given note.

type DB

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

DB holds the connections to a SQLite database.

func Open

func Open(path string) (*DB, error)

Open creates a new DB instance for the SQLite database at the given path.

func OpenInMemory

func OpenInMemory() (*DB, error)

OpenInMemory creates a new in-memory DB instance.

func (*DB) Close

func (db *DB) Close() error

Close terminates the connections to the SQLite database.

func (*DB) Migrate

func (db *DB) Migrate() (needsReindexing bool, err error)

Migrate upgrades the SQL schema of the database.

func (*DB) WithTransaction

func (db *DB) WithTransaction(fn TxFn) error

WithTransaction creates a new transaction and handles rollback/commit based on the error object returned by the TxFn closure.

type LazyStmt

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

LazyStmt is a wrapper around a sql.Stmt which will be evaluated on first use.

func NewLazyStmt

func NewLazyStmt(tx *sql.Tx, query string) *LazyStmt

NewLazyStmt creates a new lazy statement bound to the given transaction.

func (*LazyStmt) Exec

func (s *LazyStmt) Exec(args ...interface{}) (sql.Result, error)

func (*LazyStmt) Query

func (s *LazyStmt) Query(args ...interface{}) (*sql.Rows, error)

func (*LazyStmt) QueryRow

func (s *LazyStmt) QueryRow(args ...interface{}) (*sql.Row, error)

func (*LazyStmt) Stmt

func (s *LazyStmt) Stmt() (*sql.Stmt, error)

type NoteDAO

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

NoteDAO persists notes in the SQLite database. It implements the core port note.Finder.

func NewNoteDAO

func NewNoteDAO(tx Transaction, logger util.Logger) *NoteDAO

NewNoteDAO creates a new instance of a DAO working on the given database transaction.

func (*NoteDAO) Add

func (d *NoteDAO) Add(note note.Metadata) (core.NoteId, error)

Add inserts a new note to the index.

func (*NoteDAO) Find

func (d *NoteDAO) Find(opts note.FinderOpts) ([]note.Match, error)

Find returns all the notes matching the given criteria.

func (*NoteDAO) Indexed

func (d *NoteDAO) Indexed() (<-chan paths.Metadata, error)

Indexed returns file info of all indexed notes.

func (*NoteDAO) Remove

func (d *NoteDAO) Remove(path string) error

Remove deletes the note with the given path from the index.

func (*NoteDAO) Update

func (d *NoteDAO) Update(note note.Metadata) (core.NoteId, error)

Update modifies an existing note.

type NoteIndexer added in v0.2.0

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

NoteIndexer persists note indexing results in the SQLite database. It implements the core port note.Indexer and acts as a facade to the DAOs.

func NewNoteIndexer added in v0.2.0

func NewNoteIndexer(notes *NoteDAO, collections *CollectionDAO, logger util.Logger) *NoteIndexer

func (*NoteIndexer) Add added in v0.2.0

func (i *NoteIndexer) Add(metadata note.Metadata) (core.NoteId, error)

Add indexes a new note from its metadata.

func (*NoteIndexer) Indexed added in v0.2.0

func (i *NoteIndexer) Indexed() (<-chan paths.Metadata, error)

Indexed returns the list of indexed note file metadata.

func (*NoteIndexer) Remove added in v0.2.0

func (i *NoteIndexer) Remove(path string) error

Remove deletes a note from the index.

func (*NoteIndexer) Update added in v0.2.0

func (i *NoteIndexer) Update(metadata note.Metadata) error

Update updates the metadata of an already indexed note.

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	ExecStmts(stmts []string) error
	Prepare(query string) (*sql.Stmt, error)
	PrepareLazy(query string) *LazyStmt
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Transaction is an interface that models the standard transaction in database/sql.

To ensure TxFn funcs cannot commit or rollback a transaction (which is handled by `WithTransaction`), those methods are not included here.

type TxFn

type TxFn func(tx Transaction) error

A Txfn is a function that will be called with an initialized Transaction object that can be used for executing statements and queries against a database.

Jump to

Keyboard shortcuts

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