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.

42 lines
585 B

  1. package Database
  2. import (
  3. "database/sql"
  4. _ "github.com/mattn/go-sqlite3"
  5. "PackageManager/Variables"
  6. )
  7. var (
  8. DB *sql.DB
  9. )
  10. func init() {
  11. var e error
  12. DB, e = sql.Open("sqlite3", Variables.DatabaseName)
  13. if e != nil {
  14. panic(e)
  15. }
  16. }
  17. func InitDB() error {
  18. var (
  19. sqlStmt string
  20. e error
  21. )
  22. sqlStmt = `
  23. CREATE TABLE IF NOT EXISTS filesystem_hash (
  24. id INTEGER NOT NULL PRIMARY KEY,
  25. path VARCHAR(256),
  26. hash VARCHAR(64),
  27. created_at INTEGER DEFAULT CURRENT_TIMESTAMP,
  28. updated_at INTEGER
  29. )
  30. `
  31. _, e = DB.Exec(sqlStmt)
  32. if e != nil {
  33. return e
  34. }
  35. return nil
  36. }