2022-04-09 22:58:54 +01:00
|
|
|
/*
|
|
|
|
Orion --- Speech to text bot
|
|
|
|
|
|
|
|
Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package core
|
|
|
|
|
|
|
|
import "github.com/cockroachdb/pebble"
|
|
|
|
|
|
|
|
|
|
|
|
type DB struct {
|
|
|
|
conn *pebble.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreateDB(path *string) (*DB, error){
|
2022-04-09 23:02:30 +01:00
|
|
|
conn, err := pebble.Open(*path, &pebble.Options{})
|
2022-04-09 22:58:54 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &DB{
|
|
|
|
conn,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (db *DB) Set(key *string, value *[]byte) error {
|
|
|
|
// Because of our use case we will only use string keys/values
|
|
|
|
return db.conn.Set([]byte(*key), *value, pebble.Sync)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *DB) Get(key *string) (*[]byte, error) {
|
|
|
|
value, closer, err := db.conn.Get([]byte(*key))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer closer.Close()
|
|
|
|
|
|
|
|
return &value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (db *DB) Close(){
|
|
|
|
db.conn.Close()
|
|
|
|
}
|