Limit the retrieved books

Report a typo

Emma is working with an in-memory version of the library.db SQLite database; below, you can see the database diagram:

library database

She wants to create a Go program that retrieves Book records whose title begins with "The" and to limit the total number of retrieved Book records to only 5; finally, her program should print all the retrieved records using a for...range loop.

Emma has written some code but needs your help to finish her Go program. Please help Emma write the additional required code to finish her program.

Tip: You will need to use string conditions with the LIKE operator and the string pattern "The%" to solve this task!

Write a program in Go
package main

import (
"fmt"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
"time"
)

// DO NOT modify the model declarations below!
type Author struct { // Model for the `authors` table
gorm.Model
Name string
Books []Book `gorm:"many2many:author_books"`
}

type Book struct { // Model for the `books` table
gorm.Model
Title string
DatePublished time.Time
PublisherID uint
Authors []Author `gorm:"many2many:author_books"`
}

type Publisher struct { // Model for the `publishers` table
gorm.Model
Name string
Books []Book
}

// nolint:gomnd // DO NOT delete this comment!
func main() {
db := createDB() // DO NOT delete this line! it creates the in-memory `library` database

var books []Book
___

Create a free account to access the full topic