models

package
v0.0.0-...-96a7448 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*bolt.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

func GetOrCreateDB(dbFileName string) (*DB, error)

*

  • <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

func (db *DB) AddNotebook(notebook Notebook) error

*

  • 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

func (db *DB) AddNotes(notebookName string, noteContents ...string) error

*

  • 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

func (db *DB) DeleteNotes(notebookName string, noteIds ...uint64) error

*

  • 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

func (db *DB) GetAllNotebookNames() ([]string, error)

*

  • Retrieves all notebook names
  • - delegates actual work to 'getNotebooksInRootBucket' function

func (*DB) GetAllNotebooks

func (db *DB) GetAllNotebooks() ([]Notebook, error)

*

  • Retrieves all notebooks (along with their notes)
  • - deletegates actual work to 'getNotebooksInRootBucket' function
  • // TODO: use this method in Dump()

func (*DB) GetNote

func (db *DB) GetNote(notebookName string, noteId uint64) (Note, error)

*

  • Retreives note with a given id
  • param: uint64 noteId
  • return: (Note, error)

func (*DB) GetNotebook

func (db *DB) GetNotebook(notebookName string) (Notebook, error)

*

  • 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

func (db *DB) NoteExists(notebookName string, noteId uint64) (bool, error)

*

  • Returns whether or not note with a given id exists
  • in the given notebook or not

func (*DB) NotebookExists

func (db *DB) NotebookExists(notebookName string) (bool, error)

*

  • Returns whether or not notebook by given name exists

func (*DB) RmNotebook

func (db *DB) RmNotebook(notebookName string) error

*

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

type Note

type Note struct {
	// TODO: explore allowing 'naming' notes within a notebook
	//Title   string `json:"title"`
	Id      uint64 `json:"id"`
	Content string `json:"content"`
}

*

  • DTO for a Note within a Notebook

type Notebook

type Notebook struct {
	Name  string `json:"name"`
	Notes []Note `json:"notes"`
}

*

  • DTO for Notebook

Jump to

Keyboard shortcuts

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