PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
880 B

package Database
import (
"database/sql"
"time"
_ "github.com/mattn/go-sqlite3"
bolt "go.etcd.io/bbolt"
"PackageManager/Variables"
)
var (
DB *sql.DB
FsDB *bolt.DB
)
func init() {
var e error
// Initialise sqlite3 database for package versioning
DB, e = sql.Open("sqlite3", Variables.DatabaseName)
if e != nil {
panic(e)
}
// Initialise bolt db for filesystem hashing
FsDB, e = bolt.Open(Variables.FsHashDatabaseName, 0600, &bolt.Options{
Timeout: 5 * time.Second,
})
if e != nil {
panic(e)
}
}
func InitDB() error {
var (
tx *bolt.Tx
e error
)
tx, e = FsDB.Begin(true)
if e != nil {
return e
}
defer tx.Rollback()
_, e = tx.CreateBucketIfNotExists(Variables.FsHashIndexBucket)
if e != nil {
return e
}
_, e = tx.CreateBucketIfNotExists(Variables.FsHashPicksBucket)
if e != nil {
return e
}
e = tx.Commit()
return e
}