Retrieving the first and last players

Report a typo

Philip is a huge fan of football, he has a Go program that creates an in-memory SQLite database with the players table that has records of his favorite football players.

After creating the in-memory players database, Philip wants to retrieve the firstPlayer and the lastPlayer from the database, and then print the players' Name, LastName, and the Team they are currently playing on, for example:

Lionel Messi Paris Saint-Germain

Your task is to help Philip write the required additional code to retrieve the firstPlayer and the lastPlayer from the database and then print the players' data.

Write a program in Go
package main

import (
"fmt"
"log"

"gorm.io/driver/sqlite"
"gorm.io/gorm"
)

type Player struct {
ID uint `gorm:"primaryKey"`
Name string
LastName string `gorm:"column:last_name"`
Team string
}

func main() {
// DO NOT delete the code block below!
// it connects to an in-memory SQLite DB and then populates 'players' with data!
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
if err != nil {
log.Fatal(err)
}
err = db.AutoMigrate(&Player{})
if err != nil {
log.Fatal(err)
}
populateDatabase(db)

// Create the firstPlayer and lastPlayer variables of the Player type below:
var ?, ? ?

// Get the First and Last players from the database:
db.?(?)
db.?(?)
___

Create a free account to access the full topic