import "upper.io/db.v3" import "upper.io/db.v3/mysql" // Database connection settings. var settings = mysql.ConnectionURL{ Host: "localhost", Database: "mydatabase", User: "root", Password: "", } // Connect to the database. sess, err := db.Open(mysql.Adapter, settings) if err != nil { panic(err) } defer sess.Close() // Query for all users. res := sess.Query("SELECT * FROM users") // Get the result count. count, err := res.Count() if err != nil { panic(err) } fmt.Printf("Total users: %d\n", count)
import "upper.io/db.v3" import "upper.io/db.v3/mysql" // Database connection settings. var settings = mysql.ConnectionURL{ Host: "localhost", Database: "mydatabase", User: "root", Password: "", } // Connect to the database. sess, err := db.Open(mysql.Adapter, settings) if err != nil { panic(err) } defer sess.Close() // Get the "users" collection. users := sess.Collection("users") // Get the number of users. count, err := users.Find().Count() if err != nil { panic(err) } fmt.Printf("Total users: %d\n", count)In both examples, we establish a connection to a MySQL database and get the total number of users in the "users" table. We use the Result Count property provided by the go upper.io.db package to accomplish this. From the code examples, we can see that the package library used is go upper.io.db.