{"id":20144723,"url":"https://github.com/widuu/gomysql","last_synced_at":"2025-04-09T19:17:33.880Z","repository":{"id":15478981,"uuid":"18212531","full_name":"widuu/gomysql","owner":"widuu","description":"golang mysql orm","archived":false,"fork":false,"pushed_at":"2014-03-29T00:57:01.000Z","size":128,"stargazers_count":24,"open_issues_count":0,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T19:17:28.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.widuu.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/widuu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-28T13:15:29.000Z","updated_at":"2025-04-09T06:06:02.000Z","dependencies_parsed_at":"2022-08-04T04:45:24.984Z","dependency_job_id":null,"html_url":"https://github.com/widuu/gomysql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widuu%2Fgomysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widuu%2Fgomysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widuu%2Fgomysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/widuu%2Fgomysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/widuu","download_url":"https://codeload.github.com/widuu/gomysql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094988,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T22:11:52.086Z","updated_at":"2025-04-09T19:17:33.861Z","avatar_url":"https://github.com/widuu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"gomysql\n[![Build Status](https://drone.io/github.com/widuu/gomysql/status.png)](https://drone.io/github.com/widuu/gomysql/latest)\n===\n**[官方网站](http://www.widuu.com)**\n\n###介绍\n\n gomysql是基于go-sql-driver基础上开发的orm，这是一个轻量级的库。它会使数据库的增删改查变得非常容易。当然也是测试开发版，会一直优化和更新！请时刻关注我们\n\n###安装\n    \n\tgo get github.com/go-sql-driver/mysql\n    go get github.com/widuu/goini\n\tgo get github.com/widuu/gomysql\n\n###依赖的包\n\n  mysql :[github.com/Go-SQL-Driver/MySQL](https://github.com/Go-SQL-Driver/MySQL)\n\n  goini :[github.com/widuu/goini](https://github.com/widuu/goini)\n\n###使用教程\n\n\u003e设置配置文件\n\n\t[database]\n\tusername = mysql username\n\tpassword = mysql password\n\thostname = mysql host\n\tcharset =  mysql charset\n\tdatabase = database name\n\tport = \t   mysql port\n\n\u003e**初始化配置**\n\n\n    c, _ := gomysql.SetConfig(\"./conf/conf.ini\") //根据配置文件，连接数据库\n\n\u003e查询数据\n\n    t := c.SetTable(\"user\")                      //设置要处理的表名\n    data := t.FindOne()                          //查询表的一条数据，返回map[int]map[string]string格式\n    gomysql.Print(data)                          //打印数据信息，返回如下截图的数据格式\n\n![gomysql_print](http://yun.widuu.com/gomysql_print.png)\n\n    data := t.Fileds(\"id\", \"password\", \"username\").Where(\"id =12\").FindOne() //Fileds 查询字段,Where where条件FindOne()查询一条\n    //limit sql中的limit OrderBy sql中查询的OrderBy\n    data  = c.SetTable(\"user\").Fileds(\"id\", \"password\", \"username\").Where(\"id\u003e1\").Limit(1, 5).OrderBy(\"id Desc\").FindAll() \n    data  = t.FindAll() //查询所有数据，其中OrderBy() Limit() Where() Fileds()等设置条件\n    gomysql.Print(data) //查询的数据都可以用Print()方法友好打印出来信息\n\n\u003e添加数据\n\n     var value = make(map[string]interface{})  //设置map存储数据，map[key]value\n     value[\"password\"] = \"mima3\"    \n     value[\"username\"] = \"xiaowei\"\n     value[\"id\"] = 10\n     t := c.SetTable(\"user\")                   //设置增加的数据表\n     t.SetPk(\"id\")                             //设置主键自增的字段名称\n     i,err := t.Insert(value)                  // 插入数据，返回增加个数和错误信息。返回最后增长的id和错误信息\n\n\u003e修改数据\n\n    var value = make(map[string]interface{})\n    value[\"password\"] = \"mima3\"\n    value[\"username\"] = \"xiaowei\"\n    n, err := c.SetTable(\"user\").Where(\"id =5\").Update(value)  //设置表，条件和修改的内容，返回影响条数和错误信息\n\n\u003e删除数据\n\n    n, err := c.SetTable(\"user\").Delete(\"id = 6\")   //设置删除的表和数据，返回影响条数和错误信息\n\n\u003e关联操作\n\nINNER JOIN \n\n\tt := c.SetTable(\"user\")\n\t//下面相当于sql语句，打印出是Select user.id,data.keywords,user.username,user.password from user INNER JOIN data ON user.id = data.id\n\tdata := t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").Join(\"data\", \"user.id = data.id\").FindAll()\n\tfmt.Println(data)\n\nLEFT JOIN\n\n\t t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").LeftJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\nRIGHT JOIN\n \t\n\t t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").RightJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\nFULL　JOIN\n\t\n     data := t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").RightJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\n\u003e自定义sql语句\n\n\t// Query()方法 是自定义sql语句的\n    \ninsert类型的数据\n\n\tn := t.Query(\"INSERT INTO user (`username`,`password`) VALUES ('xiaoweitest','xiaowei')\") //返回最后增长的id\n\nupdate|delete\n\n\t //update\n     n := c.Query(\"update user set username='ceshishenma' where id =17 \")\n\t fmt.Println(n) //1 返回受影响行数\n\t\n     //delete\n\t n := c.Query(\"delete from user where id=16 \")\n\t fmt.Println(n) //1 返回受影响行数\n\nselect \n\n    data := c.Query(\"select username,password from user\")\n\tfmt.Println(data) //返回map[int]map[string]string 结构的所有数据\n\n   \n\n\u003e关闭数据库\n\n    c.DbClose()     //关闭数据库\n\n\n---\n\n##English Document\n\n**[The Offcial Website](http://www.widuu.com)**\n\n###Introduction\n\n Gomysql 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\n\n###Install\n\n    go get github.com/widuu/gomysql\n\n###Rely on the package\n\n  mysql :[github.com/Go-SQL-Driver/MySQL](https://github.com/Go-SQL-Driver/MySQL)\n\n  goini :[github.com/widuu/goini](https://github.com/widuu/goini)\n\n###Using the tutorial\n\n\u003eSet the configuration file\n\n    [database]\n    username = mysql username\n    password = mysql password\n    hostname = mysql host\n    charset =  mysql charset\n    database = database name\n    port =     mysql port\n\n\u003e**Initialize the configuration**\n\n\n    c, _ := gomysql.SetConfig(\"./conf/conf.ini\") //According to the configuration files, connect to the database\n\n\u003eQuery data\n\n    t := c.SetTable(\"user\")                      //set up the table name\n    data := t.FindOne()                          //A data query，return map[int]map[string]string format\n    gomysql.Print(data)                          //Print data information, and return the following screenshots data formats\n\n![gomysql_print](http://yun.widuu.com/gomysql_print.png)\n\n    data := t.Fileds(\"id\", \"password\", \"username\").Where(\"id =12\").FindOne() //Fileds Query field,Where where conditions FindOne() query a data\n    //limit - sql limit,OrderBy - sql OrderBy\n    data  = c.SetTable(\"user\").Fileds(\"id\", \"password\", \"username\").Where(\"id\u003e1\").Limit(1, 5).OrderBy(\"id Desc\").FindAll() \n    data  = t.FindAll() //Query all the data, including OrderBy () Limit () the Where () Fileds () set conditions\n    gomysql.Print(data) //Query data can use the Print () method of friendly printed information\n\n\u003eInsert data\n\n     var value = make(map[string]interface{})  //Set the map data is stored, the map [key] the value\n     value[\"password\"] = \"mima3\"    \n     value[\"username\"] = \"xiaowei\"\n     value[\"id\"] = 10\n     t := c.SetTable(\"user\")                   //Set up to increase the data tables\n     t.SetPk(\"id\")                             //Set the primary key on the field name\n     i,err := t.Insert(value)                  // Insert data, returns the number increase and error information.Returns the last growth id and error message\n\n\u003eUpdata data\n\n    var value = make(map[string]interface{})\n    value[\"password\"] = \"mima3\"\n    value[\"username\"] = \"xiaowei\"\n    n, 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 information\n\n\u003eDelete data\n\n    n, err := c.SetTable(\"user\").Delete(\"id = 6\")   //Article, set the table and data delete, return to influence the number and the error information\n\n\u003eAssociated operation\n\nINNER JOIN \n\n\tt := c.SetTable(\"user\")\n\t\n\t//Equivalent to a SQL statement below, print out is \n\t//Select user.id,data.keywords,user.username,user.password from user INNER JOIN data ON user.id = data.id\n\n\tdata := t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").Join(\"data\", \"user.id = data.id\").FindAll()\n\tfmt.Println(data)\n\nLEFT JOIN\n\n\t t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").LeftJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\nRIGHT JOIN\n \t\n\t t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").RightJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\nFULL　JOIN\n\t\n     data := t.Fileds(\"user.id\", \"data.keywords\", \"user.username\", \"user.password\").RightJoin(\"data\", \"user.id = data.id\").FindAll()\n\t fmt.Println(data)\n\n\u003e自定义sql语句\n\n\t// Query()function Is a custom SQL statement\n    \ninsert\n\n\tn := t.Query(\"INSERT INTO user (`username`,`password`) VALUES ('xiaoweitest','xiaowei')\") //Return the id of the growth\n\nupdate|delete\n\n\t //update\n     n := c.Query(\"update user set username='ceshishenma' where id =17 \")\n\t fmt.Println(n) //1 Return the affected rows\n\t\n     //delete\n\t n := c.Query(\"delete from user where id=16 \")\n\t fmt.Println(n) //1 Return the affected rows\n\nselect \n\n    data := c.Query(\"select username,password from user\")\n\tfmt.Println(data) //return map[int]map[string]string All of the data structure\n\n   \n\n\u003eClose the database\n\n    c.DbClose()     //close the database\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiduu%2Fgomysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiduu%2Fgomysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiduu%2Fgomysql/lists"}