网站首页图片做多大,济南高新区 网站制作,wordpress段代码,贵阳能做网站的公司gomysql###介绍gomysql是基于go-sql-driver基础上开发的orm#xff0c;这是一个轻量级的库。它会使数据库的增删改查变得非常容易。当然也是测试开发版#xff0c;会一直优化和更新#xff01;请时刻关注我们###安装go get github.com/go-sql-driver/mysqlgo get github.com…gomysql###介绍gomysql是基于go-sql-driver基础上开发的orm这是一个轻量级的库。它会使数据库的增删改查变得非常容易。当然也是测试开发版会一直优化和更新请时刻关注我们###安装go get github.com/go-sql-driver/mysqlgo get github.com/widuu/goinigo get github.com/widuu/gomysql###依赖的包###使用教程设置配置文件[database]username mysql usernamepassword mysql passwordhostname mysql hostcharset mysql charsetdatabase database nameport mysql port初始化配置c, _ : gomysql.SetConfig(./conf/conf.ini) //根据配置文件连接数据库查询数据t : c.SetTable(user) //设置要处理的表名data : t.FindOne() //查询表的一条数据返回map[int]map[string]string格式gomysql.Print(data) //打印数据信息返回如下截图的数据格式data : t.Fileds(id, password, username).Where(id 12).FindOne() //Fileds 查询字段,Where where条件FindOne()查询一条//limit sql中的limit OrderBy sql中查询的OrderBydata c.SetTable(user).Fileds(id, password, username).Where(id1).Limit(1, 5).OrderBy(id Desc).FindAll()data t.FindAll() //查询所有数据其中OrderBy() Limit() Where() Fileds()等设置条件gomysql.Print(data) //查询的数据都可以用Print()方法友好打印出来信息添加数据var value make(map[string]interface{}) //设置map存储数据map[key]valuevalue[password] mima3value[username] xiaoweivalue[id] 10t : c.SetTable(user) //设置增加的数据表t.SetPk(id) //设置主键自增的字段名称i,err : t.Insert(value) // 插入数据返回增加个数和错误信息。返回最后增长的id和错误信息修改数据var value make(map[string]interface{})value[password] mima3value[username] xiaowein, err : c.SetTable(user).Where(id 5).Update(value) //设置表条件和修改的内容返回影响条数和错误信息删除数据n, err : c.SetTable(user).Delete(id 6) //设置删除的表和数据返回影响条数和错误信息关联操作INNER JOINt : c.SetTable(user)//下面相当于sql语句打印出是Select user.id,data.keywords,user.username,user.password from user INNER JOIN data ON user.id data.iddata : t.Fileds(user.id, data.keywords, user.username, user.password).Join(data, user.id data.id).FindAll()fmt.Println(data)LEFT JOINt.Fileds(user.id, data.keywords, user.username, user.password).LeftJoin(data, user.id data.id).FindAll()fmt.Println(data)RIGHT JOINt.Fileds(user.id, data.keywords, user.username, user.password).RightJoin(data, user.id data.id).FindAll()fmt.Println(data)FULL JOINdata : t.Fileds(user.id, data.keywords, user.username, user.password).RightJoin(data, user.id data.id).FindAll()fmt.Println(data)自定义sql语句// Query()方法 是自定义sql语句的insert类型的数据n : t.Query(INSERT INTO user (username,password) VALUES (xiaoweitest,xiaowei)) //返回最后增长的idupdate|delete//updaten : c.Query(update user set usernameceshishenma where id 17 )fmt.Println(n) //1 返回受影响行数//deleten : c.Query(delete from user where id16 )fmt.Println(n) //1 返回受影响行数selectdata : c.Query(select username,password from user)fmt.Println(data) //返回map[int]map[string]string 结构的所有数据关闭数据库c.DbClose() //关闭数据库##English Document###IntroductionGomysql is based on the go - SQL - driver based on orm, this is a lightweight library.It allows the database to add delete very easily.Of course is also testing the development version, will continue to optimize and update!Please attention to us###Installgo get github.com/widuu/gomysql###Rely on the package###Using the tutorialSet the configuration file[database]username mysql usernamepassword mysql passwordhostname mysql hostcharset mysql charsetdatabase database nameport mysql portInitialize the configurationc, _ : gomysql.SetConfig(./conf/conf.ini) //According to the configuration files, connect to the databaseQuery datat : c.SetTable(user) //set up the table namedata : t.FindOne() //A data queryreturn map[int]map[string]string formatgomysql.Print(data) //Print data information, and return the following screenshots data formatsdata : t.Fileds(id, password, username).Where(id 12).FindOne() //Fileds Query field,Where where conditions FindOne() query a data//limit - sql limit,OrderBy - sql OrderBydata c.SetTable(user).Fileds(id, password, username).Where(id1).Limit(1, 5).OrderBy(id Desc).FindAll()data t.FindAll() //Query all the data, including OrderBy () Limit () the Where () Fileds () set conditionsgomysql.Print(data) //Query data can use the Print () method of friendly printed informationInsert datavar value make(map[string]interface{}) //Set the map data is stored, the map [key] the valuevalue[password] mima3value[username] xiaoweivalue[id] 10t : c.SetTable(user) //Set up to increase the data tablest.SetPk(id) //Set the primary key on the field namei,err : t.Insert(value) // Insert data, returns the number increase and error information.Returns the last growth id and error messageUpdata datavar value make(map[string]interface{})value[password] mima3value[username] xiaowein, err : c.SetTable(user).Where(id 5).Update(value) //Set the table, the condition and modify the content of the article returns affect the number and the error informationDelete datan, err : c.SetTable(user).Delete(id 6) //Article, set the table and data delete, return to influence the number and the error informationAssociated operationINNER JOINt : c.SetTable(user)//Equivalent to a SQL statement below, print out is//Select user.id,data.keywords,user.username,user.password from user INNER JOIN data ON user.id data.iddata : t.Fileds(user.id, data.keywords, user.username, user.password).Join(data, user.id data.id).FindAll()fmt.Println(data)LEFT JOINt.Fileds(user.id, data.keywords, user.username, user.password).LeftJoin(data, user.id data.id).FindAll()fmt.Println(data)RIGHT JOINt.Fileds(user.id, data.keywords, user.username, user.password).RightJoin(data, user.id data.id).FindAll()fmt.Println(data)FULL JOINdata : t.Fileds(user.id, data.keywords, user.username, user.password).RightJoin(data, user.id data.id).FindAll()fmt.Println(data)自定义sql语句// Query()function Is a custom SQL statementinsertn : t.Query(INSERT INTO user (username,password) VALUES (xiaoweitest,xiaowei)) //Return the id of the growthupdate|delete//updaten : c.Query(update user set usernameceshishenma where id 17 )fmt.Println(n) //1 Return the affected rows//deleten : c.Query(delete from user where id16 )fmt.Println(n) //1 Return the affected rowsselectdata : c.Query(select username,password from user)fmt.Println(data) //return map[int]map[string]string All of the data structureClose the databasec.DbClose() //close the database