CheckDatabase checks the SQLite database file at the given path. Parameters: - databasePath: a string variable that holds the path to the SQLite database file. Returns: None.
(databasePath string)
| 67 | // |
| 68 | // Returns: None. |
| 69 | func CheckDatabase(databasePath string) { |
| 70 | // databasePath is a variable that holds the path to the SQLite database file |
| 71 | db, err := gorm.Open(sqlite.Open(databasePath), &gorm.Config{}) |
| 72 | checkErr(err) |
| 73 | |
| 74 | // Check if the history table exists, if not, create it |
| 75 | err = db.AutoMigrate(&RouterHistory{}) |
| 76 | checkErr(err) |
| 77 | err = db.AutoMigrate(&DevicesHistory{}) |
| 78 | checkErr(err) |
| 79 | // Perform CRUD operations on the history table using db.Create, db.First, db.Update, db.Delete methods |
| 80 | defer func() { |
| 81 | sqlDB, err := db.DB() |
| 82 | checkErr(err) |
| 83 | sqlDB.Close() |
| 84 | }() |
| 85 | } |
| 86 | |
| 87 | // Savetodb saves device statistics to the database. |
| 88 | // |