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

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package Database
  2. import (
  3. "database/sql"
  4. "time"
  5. _ "github.com/mattn/go-sqlite3"
  6. bolt "go.etcd.io/bbolt"
  7. "PackageManager/Variables"
  8. )
  9. var (
  10. DB *sql.DB
  11. FsDB *bolt.DB
  12. )
  13. func init() {
  14. var e error
  15. // Initialise sqlite3 database for package versioning
  16. DB, e = sql.Open("sqlite3", Variables.DatabaseName)
  17. if e != nil {
  18. panic(e)
  19. }
  20. // Initialise bolt db for filesystem hashing
  21. FsDB, e = bolt.Open(Variables.FsHashDatabaseName, 0600, &bolt.Options{
  22. Timeout: 5 * time.Second,
  23. })
  24. if e != nil {
  25. panic(e)
  26. }
  27. }
  28. func InitDB() error {
  29. var (
  30. tx *bolt.Tx
  31. e error
  32. )
  33. tx, e = FsDB.Begin(true)
  34. if e != nil {
  35. return e
  36. }
  37. defer tx.Rollback()
  38. _, e = tx.CreateBucketIfNotExists(Variables.FsHashIndexBucket)
  39. if e != nil {
  40. return e
  41. }
  42. _, e = tx.CreateBucketIfNotExists(Variables.FsHashPicksBucket)
  43. if e != nil {
  44. return e
  45. }
  46. e = tx.Commit()
  47. return e
  48. }