ntrrg / usersd
1
// Copyright 2019 Miguel Angel Rivera Notararigo. All rights reserved.
2
// This source code was released under the MIT license.
3

4
package sdb
5

6
import (
7
	"log"
8
	"os"
9
	"path/filepath"
10

11
	"github.com/blevesearch/bleve/mapping"
12
	"github.com/dgraph-io/badger/v2"
13
)
14

15
const (
16
	DatabaseDir    = "database"
17
	SearchIndexDir = "search-index"
18
)
19

20
type BleveOptions struct {
21
	Dir          string
22
	DoctypeField string
23
	DocMappings  map[string]*mapping.DocumentMapping
24
}
25

26
// Options are parameters for initializing a database.
27
type Options struct {
28
	// Database location.
29
	Directory string
30

31
	Badger badger.Options
32
	Bleve  BleveOptions
33

34
	BufferPoolSize     int  // Amount of buffers.
35
	BufferPoolMaxBytes int  // Bytes limit per buffer.
36
	BufferPoolFill     bool // Fill up the pool at DB creation.
37

38
	Logger *log.Logger
39
}
40

41
// DefaultOptions returns commonly used options for creating a database.
42 1
func DefaultOptions(dir string) Options {
43 1
	dir = filepath.Clean(dir)
44

45 1
	return Options{
46 1
		Directory: dir,
47 1
		Badger:    badger.DefaultOptions(filepath.Join(dir, DatabaseDir)),
48

49 1
		Bleve: BleveOptions{
50 1
			Dir:          filepath.Join(dir, SearchIndexDir),
51 1
			DoctypeField: "Doctype",
52 1
			DocMappings:  make(map[string]*mapping.DocumentMapping),
53 1
		},
54

55 1
		BufferPoolSize:     500,
56 1
		BufferPoolMaxBytes: 5 * 1024,
57 1
		BufferPoolFill:     false,
58

59 1
		Logger: log.New(os.Stderr, "sdb: ", log.LstdFlags),
60
	}
61
}

Read our documentation on viewing source code .

Loading