Layoffs at Chirper

Report a typo

Leon, a well-known billionaire entrepreneur, has just acquired the famous social media company Chirper. One of his first decisions as the new owner was to streamline operations, which unfortunately resulted in employee layoffs.

Chirper maintains a comprehensive record of all its employees in the employees table:

Leon has created a Go program that takes a department as input; now, he needs your help to write the additional required code to retrieve all employees who work in the input department, and then perform batch deletion on the retrieved Employee records since these employees were laid off.

This problem uses a hidden function checkDeletedRecords() to verify if you have correctly performed batch deletion on the records from the employees table.

Sample Input 1:

Engineering

Sample Output 1:

Deleted 8 Employees from the Engineering department
Write a program in Go
package main

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

type Employee struct { // Model for the `employees` table
gorm.Model
Name string
LastName string
Title string
Department string
Address string
}

func main() {
db := createDB() // DO NOT delete this line! it creates the in-memory database.

// Take as input the `department`:
var department string
fmt.Scanln(&department)

// Write the code to retrieve all employees in the `department`:
var employees ?
result := ?
if result.Error != nil {
log.Fatalf("cannot retrieve Employees: %v", result.Error)
}

// Write the code below to perform batch deletion of all employees in the `department`:
result = ?
if result.Error != nil {
log.Fatalf("cannot delete Employees: %v", result.Error)
___

Create a free account to access the full topic