sqlite

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectionDAO

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

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

func NewCollectionDAO

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

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) FindAll

func (d *CollectionDAO) FindAll(kind core.CollectionKind, sorters []core.CollectionSorter) ([]core.Collection, error)

func (*CollectionDAO) FindOrCreate

func (d *CollectionDAO) FindOrCreate(kind core.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

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) 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 LinkDAO added in v0.8.0

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

LinkDAO persists links in the SQLite database.

func NewLinkDAO added in v0.8.0

func NewLinkDAO(tx Transaction, logger util.Logger) *LinkDAO

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

func (*LinkDAO) Add added in v0.8.0

func (d *LinkDAO) Add(links []core.ResolvedLink) error

Add inserts all the outbound links of the given note.

func (*LinkDAO) FindBetweenNotes added in v0.8.0

func (d *LinkDAO) FindBetweenNotes(ids []core.NoteID) ([]core.ResolvedLink, error)

func (*LinkDAO) RemoveAll added in v0.8.0

func (d *LinkDAO) RemoveAll(id core.NoteID) error

RemoveAll removes all the outbound links of the given note.

func (*LinkDAO) SetTargetID added in v0.8.0

func (d *LinkDAO) SetTargetID(href string, id core.NoteID) error

SetTargetID updates the missing target_id for links matching the given href. FIXME: Probably doesn't work for all type of href (partial, wikilinks, etc.)

type MetadataDAO

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

MetadataDAO persists arbitrary key/value pairs in the SQLite database.

func NewMetadataDAO

func NewMetadataDAO(tx Transaction) *MetadataDAO

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

func (*MetadataDAO) Get

func (d *MetadataDAO) Get(key string) (string, error)

Get returns the value for the given key.

func (*MetadataDAO) Set

func (d *MetadataDAO) Set(key string, value string) error

Set resets the value for the given metadata key.

type NoteDAO

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

NoteDAO persists notes in the SQLite database.

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 core.Note) (core.NoteID, error)

Add inserts a new note to the index.

func (*NoteDAO) Find

func (d *NoteDAO) Find(opts core.NoteFindOpts) ([]core.ContextualNote, error)

Find returns all the notes matching the given criteria.

func (*NoteDAO) FindIdByHref added in v0.8.0

func (d *NoteDAO) FindIdByHref(href string, allowPartialHref bool) (core.NoteID, error)

func (*NoteDAO) FindIdByPath added in v0.8.0

func (d *NoteDAO) FindIdByPath(path string) (core.NoteID, error)

func (*NoteDAO) FindIdsByHref added in v0.9.0

func (d *NoteDAO) FindIdsByHref(href string, allowPartialHref bool) ([]core.NoteID, error)

func (*NoteDAO) FindMinimal

func (d *NoteDAO) FindMinimal(opts core.NoteFindOpts) ([]core.MinimalNote, error)

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 core.Note) (core.NoteID, error)

Update modifies an existing note.

type NoteIndex

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

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

func NewNoteIndex

func NewNoteIndex(db *DB, logger util.Logger) *NoteIndex

func (*NoteIndex) Add

func (ni *NoteIndex) Add(note core.Note) (id core.NoteID, err error)

Add implements core.NoteIndex.

func (*NoteIndex) Commit

func (ni *NoteIndex) Commit(transaction func(idx core.NoteIndex) error) error

Commit implements core.NoteIndex.

func (*NoteIndex) Find

func (ni *NoteIndex) Find(opts core.NoteFindOpts) (notes []core.ContextualNote, err error)

Find implements core.NoteIndex.

func (*NoteIndex) FindCollections

func (ni *NoteIndex) FindCollections(kind core.CollectionKind, sorters []core.CollectionSorter) (collections []core.Collection, err error)

FindCollections implements core.NoteIndex.

func (*NoteIndex) FindLinksBetweenNotes added in v0.8.0

func (ni *NoteIndex) FindLinksBetweenNotes(ids []core.NoteID) (links []core.ResolvedLink, err error)

FindLinksBetweenNotes implements core.NoteIndex.

func (*NoteIndex) FindMinimal

func (ni *NoteIndex) FindMinimal(opts core.NoteFindOpts) (notes []core.MinimalNote, err error)

FindMinimal implements core.NoteIndex.

func (*NoteIndex) IndexedPaths

func (ni *NoteIndex) IndexedPaths() (metadata <-chan paths.Metadata, err error)

IndexedPaths implements core.NoteIndex.

func (*NoteIndex) NeedsReindexing

func (ni *NoteIndex) NeedsReindexing() (needsReindexing bool, err error)

NeedsReindexing implements core.NoteIndex.

func (*NoteIndex) Remove

func (ni *NoteIndex) Remove(path string) error

Remove implements core.NoteIndex

func (*NoteIndex) SetNeedsReindexing

func (ni *NoteIndex) SetNeedsReindexing(needsReindexing bool) error

SetNeedsReindexing implements core.NoteIndex.

func (*NoteIndex) Update

func (ni *NoteIndex) Update(note core.Note) error

Update implements core.NoteIndex.

type RowQuerier added in v0.8.0

type RowQuerier interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

type RowScanner

type RowScanner interface {
	Scan(dest ...interface{}) error
}

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