sqlnullstring etc
crispy-caesus 114518720+crispy-caesus@users.noreply.github.com
Thu, 16 Jan 2025 14:15:11 +0100
5 files changed,
40 insertions(+),
14 deletions(-)
M
main.go
→
main.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.go
→
sql.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.go
→
structs.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 }