November 2018
Intermediate to advanced
346 pages
8h 12m
English
Firstly, a quick refresher: currently, the data package does not use DI, and therefore we cannot pass in the *sql.DB like we did in the previous example. The function currently looks as shown in the following code:
// Save will save the supplied person and return the ID of the newly // created person or an error.// Errors returned are caused by the underlying database or our connection// to it.func Save(in *Person) (int, error) { db, err := getDB() if err != nil { logging.L.Error("failed to get DB connection. err: %s", err) return defaultPersonID, err } // perform DB insert query := "INSERT INTO person (fullname, phone, currency, price) VALUES (?, ?, ?, ?)" result, err := db.Exec(query, in.FullName, in.Phone
Read now
Unlock full access