index — walletdrain @ 37a7078120e9319c3443b1dfadf53f59c571be81

Little app to track my spendings, for the time being only for music

sqlnullstring etc
crispy-caesus 114518720+crispy-caesus@users.noreply.github.com
Thu, 16 Jan 2025 14:15:11 +0100
commit

37a7078120e9319c3443b1dfadf53f59c571be81

parent

5d39f632a1e5e772b264f03d1ca75202185340c3

5 files changed, 40 insertions(+), 14 deletions(-)

jump to
A .gitignore

@@ -0,0 +1,2 @@

+*.db +walletdrain
M main.gomain.go

@@ -11,34 +11,40 @@ "fyne.io/fyne/v2/layout"

"fyne.io/fyne/v2/widget" ) + func tableView(w fyne.Window, category string) { items := loadCategory(category) table := widget.NewTableWithHeaders( func() (int, int) { - return len(items), 4 + return len(items), 5 }, func() fyne.CanvasObject { return widget.NewLabel("uhh, something went wrong") }, func(id widget.TableCellID, cell fyne.CanvasObject) { label := cell.(*widget.Label) + label.Truncation = fyne.TextTruncateEllipsis switch id.Col { case 0: - label.SetText(items[id.Row].name) + label.SetText(items[id.Row].name.String) case 1: - label.SetText(strconv.FormatFloat(items[id.Row].price, 'f', 2, 64) + " " + items[id.Row].currency) + label.SetText(items[id.Row].artist.String) case 2: - label.SetText(items[id.Row].seller) + label.SetText(strconv.FormatFloat(items[id.Row].price, 'f', 2, 64) + " " + items[id.Row].currency.String) case 3: - label.SetText(items[id.Row].purchase_date) + label.SetText(items[id.Row].seller.String) + case 4: + label.SetText(items[id.Row].purchase_date.String) } }, ) + /* table.SetColumnWidth(0, 100) table.SetColumnWidth(1, 100) table.SetColumnWidth(2, 100) table.SetColumnWidth(3, 100) + */ /* headers := []string{"Name", "Price", "Seller", "Purchase Date"}

@@ -49,7 +55,19 @@ widget.NewLabel(header))

} */ - w.SetContent(table) + maxContainer := container.NewMax(table) + split := container.NewHSplit(maxContainer, widget.NewLabel("Select a column to edit")) + /* + table.OnSelected = func(id widget.TableCellID) { + editForm := widget.NewForm() + for colIndex := 0; colIndex < 4; colIndex++ { + entry := widget.NewEntry() + entry.SetText(table.Cel) + } + } + */ + + w.SetContent(split) } func mainMenu(w fyne.Window) {
M sql.gosql.go

@@ -2,7 +2,8 @@ package main

import ( "database/sql" - "fmt" + "fmt" + "log" _ "github.com/mattn/go-sqlite3" )

@@ -23,6 +24,7 @@ _, err = db.Exec(`CREATE TABLE IF NOT EXISTS music (

id INTEGER PRIMARY KEY AUTOINCREMENT, external_ids TEXT, name TEXT NOT NULL, + artist TEXT NOT NULL, price FLOAT, currency TEXT, seller TEXT,

@@ -63,13 +65,14 @@ err := rows.Scan(

&result.id, &result.external_ids, &result.name, + &result.artist, &result.price, &result.currency, &result.seller, &result.note, &result.purchase_date) if err != nil { - panic("couldn't scan sql results") + log.Print(err) } results = append(results, result) }
M structs.gostructs.go

@@ -1,13 +1,16 @@

package main +import "database/sql" + type musicItem struct { id int - external_ids string - name string + external_ids sql.NullString + name sql.NullString + artist sql.NullString price float64 - currency string - seller string - note string - purchase_date string + currency sql.NullString + seller sql.NullString + note sql.NullString + purchase_date sql.NullString }