added basic connection

This commit is contained in:
Nickiel12 2023-12-21 16:44:34 -08:00
parent 0c1b9ae392
commit 51ebc9d841

View file

@ -1,7 +1,7 @@
package main
import (
//"database/sql"
"database/sql"
"fmt"
"log"
"time"
@ -13,12 +13,12 @@ import (
)
type Transaction struct {
id int
amount decimal.Decimal
description string
account int
bucket int
date time.Time
Id int `db:"trns_id"`
Amount decimal.Decimal `db:"trns_amount"`
Description sql.NullString `db:"trns_description"`
Account int `db:"trns_account"`
Bucket sql.NullInt64 `db:"trns_bucket"`
Date time.Time `db:"trns_date"`
}
func hello(w http.ResponseWriter, req *http.Request) {
@ -51,7 +51,7 @@ func main() {
log.Print("Database successfully pinged")
transactions := []Transaction{}
err = db.Select(&transactions, "SELECT * FROM rcnt.transactions ORDER BY trns_id DESC")
err = db.Select(&transactions, "SELECT trns_id, trns_amount, trns_description, trns_account, trns_bucket, trns_date FROM rcnt.transactions ORDER BY trns_id DESC")
if err != nil {
log.Fatal(err)
}
@ -59,7 +59,11 @@ func main() {
log.Print("Select has been run")
for _, trns := range transactions {
log.Print(fmt.Sprintf("%#v : %#v", trns.amount, trns.id))
if trns.Description.Valid {
log.Print(fmt.Sprintf("%v : %#v", trns.Amount, trns.Id))
} else {
log.Print("amount invalid")
}
}
log.Print("select all run is done")