Retrieving the last movie

Report a typo

Edwin has a Go program that creates an in-memory SQLite database with the movies table that has records of his favorite movies.

After creating the in-memory database, Edwin wants his program to retrieve the last record in the movies table, save it within the lastMovie variable and then print the retrieved record to the terminal.

Please help Edwin write the required additional code to achieve this task.

Write a program in Go
package main

import (
"fmt"
"log"

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

type Movie struct {
MovieID uint `gorm:"primaryKey"`
Name string
}

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

// Create the `lastMovie` variable of the `Movie` type below:
var lastMovie ?

// Retrieve the last record from the `movies` table below:
?

// Print the retrieved `lastMovie` record below:
fmt.Println(?)
___

Create a free account to access the full topic