func CreateDriveTable(tx dbutil.DBLike) error { stmt, err := tx.Prepare(` CREATE TABLE Drive ( ID INTEGER PRIMARY KEY, Name VARCHAR(255), SerialNumber VARCHAR(255) ); `) if err != nil { return err } _, err = stmt.Exec() if err != nil { return err } return nil }
func (s *Drive) Delete(tx dbutil.DBLike) error { stmt, err := tx.Prepare("DELETE FROM Drive WHERE ID = ?") if err != nil { return err } _, err = stmt.Exec(s.ID) if err != nil { return err } return nil }
func (s *Drive) Insert(tx dbutil.DBLike) error { stmt, err := tx.Prepare("INSERT INTO Drive(Name,SerialNumber) VALUES(?,?)") if err != nil { return err } result, err := stmt.Exec(s.Name, s.SerialNumber) if err != nil { return err } s.ID, err = result.LastInsertId() if err != nil { return err } return nil }
func (s *Drive) Update(tx dbutil.DBLike) error { stmt, err := tx.Prepare(fmt.Sprintf("UPDATE Drive(%s) VALUES(?,?,?) WHERE Drive.ID = ?", sqlFieldsForDrive())) if err != nil { return err } params := []interface{}{s.ID, s.Name, s.SerialNumber} params = append(params, s.ID) _, err = stmt.Exec(params...) if err != nil { return err } return nil }
func (s *File) Insert(tx dbutil.DBLike) error { stmt, err := tx.Prepare("INSERT INTO File(DriveID,Path,Hash,Thumbnail,Size,CreatedAt,ToBeDeleted) VALUES(?,?,?,?,?,?,?)") if err != nil { return err } result, err := stmt.Exec(s.DriveID, s.Path, s.Hash, s.Thumbnail, s.Size, s.CreatedAt, s.ToBeDeleted) if err != nil { return err } s.ID, err = result.LastInsertId() if err != nil { return err } return nil }
func (s *File) Update(tx dbutil.DBLike) error { stmt, err := tx.Prepare(fmt.Sprintf("UPDATE File(%s) VALUES(?,?,?,?,?,?,?,?) WHERE File.ID = ?", sqlFieldsForFile())) if err != nil { return err } params := []interface{}{s.ID, s.DriveID, s.Path, s.Hash, s.Thumbnail, s.Size, s.CreatedAt, s.ToBeDeleted} params = append(params, s.ID) _, err = stmt.Exec(params...) if err != nil { return err } return nil }
func CreateFileTable(tx dbutil.DBLike) error { stmt, err := tx.Prepare(` CREATE TABLE File ( ID INTEGER PRIMARY KEY, DriveID INTEGER, Path VARCHAR(255), Hash VARCHAR(255), Thumbnail VARCHAR(255), Size INTEGER, CreatedAt DATETIME, ToBeDeleted BOOLEAN ); `) if err != nil { return err } _, err = stmt.Exec() if err != nil { return err } return nil }