package main

import (
	"database/sql"
	"log"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	connectionString := "kontor:kontor@tcp(127.0.0.1:3306)/kontor?parseTime=true"
	db, err := sql.Open("mysql", connectionString)
	if err != nil {
		log.Printf("setup database error: %v", err)
		return
	}
	db.SetConnMaxLifetime(time.Minute * 3)
	db.SetMaxOpenConns(10)
	db.SetMaxIdleConns(10)
	log.Println("Database connected")

	rows, err := db.Query("SELECT id, created_date, last_modified_date, version, url, title, review FROM media_file")
	if err != nil {
		log.Fatal((err.Error()))
	}
	defer rows.Close()
	var rec MediaFile
	for rows.Next() {
		err = rows.Scan(&rec.ID, &rec.CreatedDate, &rec.LastModifiedDate, &rec.Version, &rec.Url, &rec.Title, &rec.Review)
		if err != nil {
			log.Fatal(err.Error())
		}
		log.Println(rec, string(rec.Url), string(rec.Title))
	}
}
