-1

For my project, I have to use a variable which contains user input for build my query in the models. The user input is recover in my login controller.

    username := l.GetString("username")

I need it in my query in the models for the WHERE

    sqldb.Open(os.Getenv("driverdb"), os.Getenv("paramsdb"))
    query := sqldb.QueryAssociativeArray("My query = dbrole.id WHERE login =" + pq.QuoteLiteral(username) + ";")
    sqldb.Close()
Kentosh
  • 11
  • 3

1 Answers1

0

With Beego you have the option of using the ORM or a Raw query

Assuming you have the initial config of the model Registered for the ORM approach you do something like:

o := orm.NewOrm()
user := User{Username: "Kentosh"}

err := o.Read(&user)
fmt.Printf("ERR: %v\n", err)
fmt.Println(user)

If you want to do it with a Raw query you use it like:

var user User
num, err := o.Raw("SELECT id FROM user WHERE username = ?", "ketosh").Values(&user)
fmt.Println(user)
ziur
  • 17
  • 1