Documentation ¶
Index ¶
- type DB
- func (db *DB) AddNotebook(notebook Notebook) error
- func (db *DB) AddNotes(notebookName string, noteContents ...string) error
- func (db *DB) DeleteNotes(notebookName string, noteIds ...uint64) error
- func (db *DB) Dump()
- func (db *DB) GetAllNotebookNames() ([]string, error)
- func (db *DB) GetAllNotebooks() ([]Notebook, error)
- func (db *DB) GetNote(notebookName string, noteId uint64) (Note, error)
- func (db *DB) GetNotebook(notebookName string) (Notebook, error)
- func (db *DB) NoteExists(notebookName string, noteId uint64) (bool, error)
- func (db *DB) NotebookExists(notebookName string) (bool, error)
- func (db *DB) RmNotebook(notebookName string) error
- type Datastore
- type Note
- type Notebook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
*
- - structure that implements the above Datastore interface
- - the concrete implementation of methods has been spread across 2 files
- 1. notebook.go: Defines DTO (struct) 'Notebook'
- - notebook-related operations
- - db-backup operation
- 2. note.go: Defines DTO (struct) 'Note'
- - note-related operations
- - Looking at the implementation of following constructor 'GetOrCreateDB'
- it can be inferred that this is just a wrapper over BoltDb's DB struct
func GetOrCreateDB ¶
*
- <Constructor for above DB struct>
- Returns an instance of DB struct by either creating a new BoltDb
- bucket for given `dbFileName` or using an existing one
- @param dbFileName string The complete (path) qualified filename of for BoltDb file
- @return (*DB, error) Tuple containing pointer to DB struct and optionally an error
func (*DB) AddNotebook ¶
*
- Adds a notebook in db
- - Puts key-value pair into 'Notebook' bucket of db
- - Key: Name of notebook
- - Value: marshalled JSON blob (bytes) of Notebook object
func (*DB) AddNotes ¶
*
- Adds notes in the given notebook
- notes' auto-increment 'Id' are generated and stored in the db by this method itself
- param: string notebookName
- param: ...Note notes
- return: error
func (*DB) DeleteNotes ¶
*
- Deletes notes with given ids from the given notebook
- param: string notebookName
- param: ...uint64 noteIds
- return: error
func (*DB) Dump ¶
func (db *DB) Dump()
*
- Prints all data of all notebooks
- Output can be piped into a file for persisting and sharing
- - delegates actual work to 'dumpCursor' method
- TODO: add CLI interface to invoke this function
func (*DB) GetAllNotebookNames ¶
*
- Retrieves all notebook names
- - delegates actual work to 'getNotebooksInRootBucket' function
func (*DB) GetAllNotebooks ¶
*
- Retrieves all notebooks (along with their notes)
- - deletegates actual work to 'getNotebooksInRootBucket' function
- // TODO: use this method in Dump()
func (*DB) GetNotebook ¶
*
- Retrieves Notebook for given 'notebookTitle' name
- - uses cursor.Seek(..) to seek through keys (notebook-names) and find matching key
- - then uses getNotesInNotebook() call to retrieve notes of that notebook
func (*DB) NoteExists ¶
*
- Returns whether or not note with a given id exists
- in the given notebook or not
func (*DB) RmNotebook ¶
*
- Removes a notebook from db
- (Removes the 'Notebook' bucket from db) *
- param: string notebookName: Name of notebook to be removed
- return: error
type Datastore ¶
type Datastore interface { // notebook-related operations NotebookExists(notebookName string) (bool, error) GetNotebook(notebookName string) (Notebook, error) GetAllNotebooks() ([]Notebook, error) GetAllNotebookNames() ([]string, error) AddNotebook(notebook Notebook) error RmNotebook(notebookName string) error // note-related operations NoteExists(notebookName string, noteId uint64) (bool, error) GetNote(notebookName string, noteId uint64) (Note, error) AddNotes(notebookName string, noteContents ...string) error DeleteNotes(notebookName string, noteIDs ...uint64) error // db-backup operation Dump() }
*
- - interface defining operations of our 'notes' datastore
- - notice the function prototypes here have one-to-one mapping with
- *almost* every command (plus it's subcommand / options)
Click to show internal directories.
Click to hide internal directories.