fyp/logic/models/classes/data_point.go

29 lines
831 B
Go
Raw Normal View History

package model_classes
import (
"database/sql"
"errors"
)
2023-10-02 21:15:31 +01:00
var FailedToGetIdAfterInsertError = errors.New("Failed to Get Id After Insert Error")
func AddDataPoint(db *sql.DB, class_id string, file_path string, mode DATA_POINT_MODE) (id string, err error) {
2023-10-10 12:28:49 +01:00
id = ""
result, err := db.Query("insert into model_data_point (class_id, file_path, model_mode, status) values ($1, $2, $3, 1) returning id;", class_id, file_path, mode)
if err != nil {
return
}
defer result.Close()
if !result.Next() {
err = FailedToGetIdAfterInsertError
return
}
err = result.Scan(&id)
return
}
func UpdateDataPointStatus(db *sql.DB, data_point_id string, status int, message *string) (err error) {
_, err = db.Exec("update model_data_point set status=$1, status_message=$2 where id=$3", status, message, data_point_id)
return
}