2023-09-22 19:22:36 +01:00
|
|
|
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")
|
|
|
|
|
2023-09-22 19:22:36 +01:00
|
|
|
func AddDataPoint(db *sql.DB, class_id string, file_path string, mode DATA_POINT_MODE) (id string, err error) {
|
|
|
|
id = ""
|
2023-10-02 21:15:31 +01:00
|
|
|
result, err := db.Query("insert into model_data_point (class_id, file_path, model_mode) values ($1, $2, $3) returning id;", class_id, file_path, mode)
|
2023-09-22 19:22:36 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2023-10-02 21:15:31 +01:00
|
|
|
defer result.Close()
|
|
|
|
if !result.Next() {
|
|
|
|
err = FailedToGetIdAfterInsertError
|
2023-09-22 19:22:36 +01:00
|
|
|
return
|
|
|
|
}
|
2023-10-02 21:15:31 +01:00
|
|
|
err = result.Scan(&id)
|
2023-09-22 19:22:36 +01:00
|
|
|
return
|
|
|
|
}
|