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 }