SQLite and Golang
Package Mainimport ("Database/sql" "FMT" "Time" _ "Github.com/mattn/go-sqlite3") func main () {//Open database, if not saved In, then create DB, err: = SQL. Open ("Sqlite3", "./foo.db") Checkerr (ERR)//CREATE TABLE sql_table: = ' CREATE table IF not EXISTS userinfo (UID INTEGER PRIMARY KEY autoincrement, username varchar (+) NULL, Departname varchar (+) NULL, created D ATE NULL); ' Db. Exec (sql_table)//Insert stmt, err: = db. Prepare ("INSERT into UserInfo (username, departname, created) VALUES (?,?,?)") Checkerr (Err) res, err: = stmt. Exec ("Wangshubo", "State Department", "2017-04-21") Checkerr (ERR) ID, err: = Res. Lastinsertid () Checkerr (err) fmt. PRINTLN (ID)//update stmt, err = db. Prepare ("Update userinfo set username=?") where uid=? ") Checkerr (Err) res, err = stmt. Exec ("wangshubo_new", id) checkerr (ERR) affect, err: = Res. Rowsaffected () Checkerr (err) fmt. PRINTLN (affect)//query rows, err: = db. Query ("SELECT * from userInfo ") Checkerr (ERR) var uid int var username string var department string var created time. Time for rows. Next () {err = rows. Scan (&uid, &username, &department, &created) checkerr (err) fmt. PRINTLN (UID) fmt. PRINTLN (username) fmt. PRINTLN (department) FMT. Println (created)} rows. Close ()//delete stmt, err = db. Prepare ("Delete from userinfo where uid=?") Checkerr (Err) res, err = stmt. Exec (ID) checkerr (ERR) affect, err = Res. Rowsaffected () Checkerr (err) fmt. PRINTLN (affect) db. Close ()}func Checkerr (err error) {if err! = Nil {panic (err)}}
1, package management, Apt-get install golang-glide and then glide init, will automatically generate GLIDE.YAML, note the need to configure the environment variable Gopath,gopath can be any directory, but Init will be prompted without the SRC directory, so you need to mkdir the SRC folder under Gopath.
2, Glide get xxxx, then will $gopath inside the package, CP to gopath the specified directory
Pro-Test available Golang SQL routines and package management