feat: started working on #23
This commit is contained in:
@@ -5,23 +5,19 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
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) {
|
||||
id = ""
|
||||
_, err = db.Exec("insert into model_data_point (class_id, file_path, model_mode) values ($1, $2, $3);", class_id, file_path, mode)
|
||||
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)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := db.Query("select id from model_data_point where class_id=$1 and file_path=$2 and model_mode=$3", class_id, file_path, mode)
|
||||
if err != nil {
|
||||
defer result.Close()
|
||||
if !result.Next() {
|
||||
err = FailedToGetIdAfterInsertError
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if !rows.Next() {
|
||||
return id, errors.New("Something worng")
|
||||
}
|
||||
|
||||
err = rows.Scan(&id)
|
||||
err = result.Scan(&id)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func ModelHasDataPoints(db *sql.DB, model_id string) (result bool, err error) {
|
||||
|
||||
var ClassAlreadyExists = errors.New("Class aready exists")
|
||||
|
||||
func CreateClass(db *sql.DB, model_id string, name string) (id string, err error) {
|
||||
func CreateClass(db *sql.DB, model_id string, order int, name string) (id string, err error) {
|
||||
id = ""
|
||||
rows, err := db.Query("select id from model_classes where model_id=$1 and name=$2;", model_id, name)
|
||||
if err != nil {
|
||||
@@ -58,25 +58,16 @@ func CreateClass(db *sql.DB, model_id string, name string) (id string, err error
|
||||
return id, ClassAlreadyExists
|
||||
}
|
||||
|
||||
_, err = db.Exec("insert into model_classes (model_id, name) values ($1, $2)", model_id, name)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rows, err = db.Query("select id from model_classes where model_id=$1 and name=$2;", model_id, name)
|
||||
rows, err = db.Query("insert into model_classes (model_id, name, class_order) values ($1, $2, $3) returning id;", model_id, name, order)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if !rows.Next() {
|
||||
return id, errors.New("Something wrong")
|
||||
return id, errors.New("Insert did not return anything")
|
||||
}
|
||||
|
||||
if err = rows.Scan(&id); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
err = rows.Scan(&id)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user