Several points of attention of Hangzhou 4--29 about Sqltest_go and Sqltest_beego

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Sqltest_go Note the point:
1. To introduce two packages
Import{_ "Github.com/go-sql-driver"; " Database/sql "}, where the first package is preceded by a" _ ", only the
The init function
2. When working with database data
Db,_: = sql. Open ("MySQL", addr)
Res: = db. Query ("SELECT * from user where username=?," Zs ") At this point res is a string of address characters
For Res. Next () {
var user user
Res. Scan (&user. Id,&user. Username,&user. Password)
} The number and type of functions in Scan () are the same as the number and type of database fields, otherwise the assignment fails


Sqltest_beego Note the point:

1.orm. RegisterDatabase ("Default", "MySQL", addr,30)//Open database driver, because Beego has been beego. Registerdriver () over MySQL

2.beego. The second parameter of router{} is prefixed with "{}"
3.this. Tplname values need to be placed in the Views folder, or the system will not find the file
4. HTTP cannot be used. Listenandserve (": 8080", nil) instead of httpport:8080 under conf/app.conf
5. var user user
O.raw (Sql,un). Queyrow (&user)//will put the retrieved first data in the user
var user []user
O.raw (Sql,un). Queryrow (&user)//will fail to assign value
var user []user

Res,_: = O.raw (Sql,un). QueryRows (&user)//only related to the name of the struct's field, type, and order, quantity Independent

6. Not clear Beego. What's the use of Registermodel (new User)?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.