Add database
This commit is contained in:
@@ -1,18 +1,29 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"time"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"log"
|
||||
"trikotwaschliste/models"
|
||||
)
|
||||
|
||||
func DbMainpage() gin.H {
|
||||
func DbMainpage(pool *pgxpool.Pool) gin.H {
|
||||
var items []models.Washlist
|
||||
|
||||
items = append(items, models.Washlist{
|
||||
Person: "Gerda",
|
||||
Date: time.Now(),
|
||||
IsWashed: true,
|
||||
})
|
||||
witems, err := pool.Query(context.Background(), "SELECT pe.name, ga.created_at, wa.washed \nFROM washlist wa\nINNER JOIN persons pe ON wa.personid = pe.id\nINNER JOIN gamedata ga ON wa.gamedataid = ga.id")
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
|
||||
var item models.Washlist
|
||||
for witems.Next() {
|
||||
err = witems.Scan(&item.Person, &item.Date, &item.IsWashed)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return gin.H{"items": items}
|
||||
}
|
||||
|
Reference in New Issue
Block a user