Brother Lian Blockchain training share go language Golang database and class operations

Source: Internet
Author: User

  The go language is the second open source programming language released by Google 2009, a relatively new programming language. Although go is not yet mature, Google's appengine and other parts of the product have started to be written using the go language. That's why Google needs the help of external programmers. "We need better libraries and tools, and the open source community can help us a lot in these areas," Parker said.


Many people like the go language, in fact, because the go language has its own unique language attributes supporting its development in the programming language community.


Brother even education go full stack and Blockchain training course skills + practical teaching concept and outline content is different from other training institutions. "Nine courses in the teaching phase combine the user's individual basic situation, the enterprise and social development needs and the latest blockchain technology application and other multidimensional content, to control the go language full stack technology as the foundation and cover the Blockchain field related application case combat.


Package Main


Import (

"Database/sql"

"FMT"

_ "Github.com/mattn/go-sqlite3"

"Log"

"OS"

)


Type Users struct {

UserId int

Uname string

}


Func Main () {

Os. Remove ("./foo.db")


DB, err: = SQL. Open ("Sqlite3", "./foo.db")

If err! = Nil {

Log. Fatal (ERR)

}

Defer db. Close ()


sql: = ' CREATE table users (UserId integer, uname text); '

Db. Exec (SQL)

sql = ' INSERT INTO users ' (Userid,uname) VALUES (1, ' Mike '); '

Db. Exec (SQL)

sql = ' INSERT INTO users ' (Userid,uname) VALUES (2, ' John '); '

Db. Exec (SQL)

Rows, err: = db. Query ("SELECT * from users")

If err! = Nil {

Log. Fatal (ERR)

}

Defer rows. Close ()

var users []users = make ([]users, 0)

For rows. Next () {

var u Users

Rows. Scan (&u.userid, &u.uname)

Users = append (Users, u)

}

Fmt. Println (Users)

}

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.