Skip to content

Commit

Permalink
Start adding documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrennmair committed Oct 27, 2023
1 parent 9e38281 commit 114168c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/dgraph-io/badger/v4"
)

// NewIndexWriter creates a new IndexWriter object. IndexWriter is used to add row data and to write
// the corresponding index data to a persistent store.
func NewIndexWriter() *IndexWriter {
return &IndexWriter{
schema: &schema{
Expand All @@ -20,6 +22,8 @@ func NewIndexWriter() *IndexWriter {
}
}

// AddRow adds a row of data and returns its row ID. The row data must be provided as map,
// where the keys contain the column names, and the values the corresponding column values.
func (idx *IndexWriter) AddRow(values map[string]string) uint32 {
idx.mtx.Lock()
defer idx.mtx.Unlock()
Expand Down Expand Up @@ -92,6 +96,8 @@ var (
keyPrefixValue = []byte{'V'}
)

// WriteToDirectory writes the index data to the provided directory. In that directory,
// a badger database is created.
func (idx *IndexWriter) WriteToDirectory(d string) error {
db, err := badger.Open(badger.DefaultOptions(d))
if err != nil {
Expand All @@ -101,6 +107,7 @@ func (idx *IndexWriter) WriteToDirectory(d string) error {
return idx.WriteToBadgerDatabase(db)
}

// WriteToBadgerDatabase writes the index data directly to a badger database.
func (idx *IndexWriter) WriteToBadgerDatabase(db *badger.DB) error {
tx := db.NewTransaction(true)

Expand Down

0 comments on commit 114168c

Please sign in to comment.