我在我的应用程序中使用 gocql 驱动程序。驱动程序有没有办法在控制台上记录查询?如何配置记录器以打印完整的查询(以及数据绑定)
package main
import (
"fmt"
"github.com/gocql/gocql"
)
var Session *gocql.Session
type Emp struct {
id string
firstName string
lastName string
age int
}
func init() {
var err error
cluster := gocql.NewCluster("localhost")
cluster.Keyspace = "cms"
Session, err = cluster.CreateSession()
if err != nil {
panic(err)
}
fmt.Println("cassandra init done")
}
func main() {
e := Emp{
id: "1",
firstName: "John",
lastName: "DOe",
age: 88,
}
createEmp(e)
}
func createEmp(emp Emp) {
fmt.Println(" **** Creating new emp ****\n", emp)
if err := Session.Query("INSERT INTO emps(empid, first_name, last_name, age) VALUES(?, ?, ?, ?)",
emp.id, emp.firstName, emp.lastName, emp.age).Exec(); err != nil {
fmt.Println("Error while inserting Emp")
fmt.Println(err)
}
}