Migrate the rest of everything from rowid to id
This commit is contained in:
@@ -10,7 +10,7 @@ type (
|
||||
db *DB
|
||||
}
|
||||
Weight struct {
|
||||
Rowid int64 `json:"rowid"`
|
||||
Id int64 `json:"id"`
|
||||
Date string `json:"date"`
|
||||
Weight float32 `json:"weight"`
|
||||
}
|
||||
@@ -20,7 +20,7 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
const weightcolumns = "rowid, date, weight"
|
||||
const weightcolumns = "id, date, weight"
|
||||
const weightAggregatedColumns = "period, amount"
|
||||
|
||||
func (w *WeightService) GetRecent() ([]Weight, error) {
|
||||
@@ -37,7 +37,7 @@ func (w *WeightService) GetRecent() ([]Weight, error) {
|
||||
|
||||
for row.Next() {
|
||||
var weight Weight
|
||||
err := row.Scan(&weight.Rowid, &weight.Date, &weight.Weight)
|
||||
err := row.Scan(&weight.Id, &weight.Date, &weight.Weight)
|
||||
if err != nil {
|
||||
log.Printf("error scanning row: %v", err)
|
||||
continue
|
||||
@@ -62,22 +62,22 @@ func (w *WeightService) Create(weight Weight) (Weight, error) {
|
||||
return weight, fmt.Errorf("error inserting weight: %v", err)
|
||||
}
|
||||
|
||||
rowid, err := res.LastInsertId()
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
return weight, fmt.Errorf("error getting last insert id: %v", err)
|
||||
}
|
||||
|
||||
return w.GetByRowid(rowid)
|
||||
return w.GetById(id)
|
||||
}
|
||||
|
||||
func (w *WeightService) GetByRowid(rowid int64) (Weight, error) {
|
||||
func (w *WeightService) GetById(id int64) (Weight, error) {
|
||||
var res Weight
|
||||
if w.db == nil || !w.db.Ready {
|
||||
return res, fmt.Errorf("cannot get weight by rowid, db is nil or is not ready")
|
||||
return res, fmt.Errorf("cannot get weight by id, db is nil or is not ready")
|
||||
}
|
||||
|
||||
row := w.db.readConn.QueryRow(fmt.Sprintf("SELECT %s from weightView WHERE rowid = ?", weightcolumns), rowid)
|
||||
err := row.Scan(&res.Rowid, &res.Date, &res.Weight)
|
||||
row := w.db.readConn.QueryRow(fmt.Sprintf("SELECT %s from weightView WHERE id = ?", weightcolumns), id)
|
||||
err := row.Scan(&res.Id, &res.Date, &res.Weight)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("error scanning row: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user