forked from naqvijafar91/cuteDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.go
More file actions
29 lines (25 loc) · 669 Bytes
/
db.go
File metadata and controls
29 lines (25 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package cutedb
//DB - Handle exported by the package
type DB struct {
storage *btree
}
//Open - Opens a new db connection at the file path
func Open(filePath string) (*DB, error) {
storage, err := initializeBtree(filePath)
if err != nil {
return nil, err
}
return &DB{storage}, nil
}
//Put - Insert a key value pair in the database
func (db *DB) Put(key string, value string) error {
pair := newPair(key, value)
if err := pair.validate(); err != nil {
return err
}
return db.storage.insert(pair)
}
//Get - Get the stored value from the database for the respective key
func (db *DB) Get(key string) (string, bool, error) {
return db.storage.get(key)
}