gomysql

###介绍

gomysql是基于go-sql-driver基础上开发的orm,这是一个轻量级的库。它会使数据库的增删改查变得非常容易。当然也是测试开发版,会一直优化和更新!请时刻关注我们

###安装

go get github.com/go-sql-driver/mysql

go get github.com/widuu/goini

go get github.com/widuu/gomysql

###依赖的包

###使用教程

设置配置文件

[database]

username = mysql username

password = mysql password

hostname = mysql host

charset = mysql charset

database = database name

port = 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中查询的OrderBy

data = c.SetTable("user").Fileds("id", "password", "username").Where("id>1").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]value

value["password"] = "mima3"

value["username"] = "xiaowei"

value["id"] = 10

t := c.SetTable("user") //设置增加的数据表

t.SetPk("id") //设置主键自增的字段名称

i,err := t.Insert(value) // 插入数据,返回增加个数和错误信息。返回最后增长的id和错误信息

修改数据

var value = make(map[string]interface{})

value["password"] = "mima3"

value["username"] = "xiaowei"

n, err := c.SetTable("user").Where("id =5").Update(value) //设置表,条件和修改的内容,返回影响条数和错误信息

删除数据

n, err := c.SetTable("user").Delete("id = 6") //设置删除的表和数据,返回影响条数和错误信息

关联操作

INNER JOIN

t := c.SetTable("user")

//下面相当于sql语句,打印出是Select user.id,data.keywords,user.username,user.password from user INNER JOIN data ON user.id = data.id

data := t.Fileds("user.id", "data.keywords", "user.username", "user.password").Join("data", "user.id = data.id").FindAll()

fmt.Println(data)

LEFT JOIN

t.Fileds("user.id", "data.keywords", "user.username", "user.password").LeftJoin("data", "user.id = data.id").FindAll()

fmt.Println(data)

RIGHT JOIN

t.Fileds("user.id", "data.keywords", "user.username", "user.password").RightJoin("data", "user.id = data.id").FindAll()

fmt.Println(data)

FULL JOIN

data := 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')") //返回最后增长的id

update|delete

//update

n := c.Query("update user set username='ceshishenma' where id =17 ")

fmt.Println(n) //1 返回受影响行数

//delete

n := c.Query("delete from user where id=16 ")

fmt.Println(n) //1 返回受影响行数

select

data := c.Query("select username,password from user")

fmt.Println(data) //返回map[int]map[string]string 结构的所有数据

关闭数据库

c.DbClose() //关闭数据库

##English Document

###Introduction

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

###Install

go get github.com/widuu/gomysql

###Rely on the package

###Using the tutorial

Set the configuration file

[database]

username = mysql username

password = mysql password

hostname = mysql host

charset = mysql charset

database = database name

port = mysql port

Initialize the configuration

c, _ := gomysql.SetConfig("./conf/conf.ini") //According to the configuration files, connect to the database

Query data

t := c.SetTable("user") //set up the table name

data := t.FindOne() //A data query,return map[int]map[string]string format

gomysql.Print(data) //Print data information, and return the following screenshots data formats

data := t.Fileds("id", "password", "username").Where("id =12").FindOne() //Fileds Query field,Where where conditions FindOne() query a data

//limit - sql limit,OrderBy - sql OrderBy

data = c.SetTable("user").Fileds("id", "password", "username").Where("id>1").Limit(1, 5).OrderBy("id Desc").FindAll()

data = t.FindAll() //Query all the data, including OrderBy () Limit () the Where () Fileds () set conditions

gomysql.Print(data) //Query data can use the Print () method of friendly printed information

Insert data

var value = make(map[string]interface{}) //Set the map data is stored, the map [key] the value

value["password"] = "mima3"

value["username"] = "xiaowei"

value["id"] = 10

t := c.SetTable("user") //Set up to increase the data tables

t.SetPk("id") //Set the primary key on the field name

i,err := t.Insert(value) // Insert data, returns the number increase and error information.Returns the last growth id and error message

Updata data

var value = make(map[string]interface{})

value["password"] = "mima3"

value["username"] = "xiaowei"

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

Delete data

n, err := c.SetTable("user").Delete("id = 6") //Article, set the table and data delete, return to influence the number and the error information

Associated operation

INNER JOIN

t := 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.id

data := t.Fileds("user.id", "data.keywords", "user.username", "user.password").Join("data", "user.id = data.id").FindAll()

fmt.Println(data)

LEFT JOIN

t.Fileds("user.id", "data.keywords", "user.username", "user.password").LeftJoin("data", "user.id = data.id").FindAll()

fmt.Println(data)

RIGHT JOIN

t.Fileds("user.id", "data.keywords", "user.username", "user.password").RightJoin("data", "user.id = data.id").FindAll()

fmt.Println(data)

FULL JOIN

data := 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 statement

insert

n := t.Query("INSERT INTO user (`username`,`password`) VALUES ('xiaoweitest','xiaowei')") //Return the id of the growth

update|delete

//update

n := c.Query("update user set username='ceshishenma' where id =17 ")

fmt.Println(n) //1 Return the affected rows

//delete

n := c.Query("delete from user where id=16 ")

fmt.Println(n) //1 Return the affected rows

select

data := c.Query("select username,password from user")

fmt.Println(data) //return map[int]map[string]string All of the data structure

Close the database

c.DbClose() //close the database

jython mysql_Jython相关推荐

  1. jython mysql_Jython中链接Oracle数据库

    实际操作环境为:Eclipse+Pydev中使用Jython链接Oracle数据库.方法有二,如下所示.(注意:将要使用的.jar文件路径加入系统变量classpath中) 一: Note:使用ojd ...

  2. jython mysql_jython安装与配置

    安装jython 0. 计算机中要安装jdk 1. 在官网www.jython.org上找到下载页面,然后下载jython-installe 2. 在cmd.exe中运行java -jar jytho ...

  3. jython mysql_jython 访问数据库的方法

    jython 访问数据库 基本上有2个方法, 使用 zxJDBC (符合Python DB API2.0规范), 或者直接使用JDBC. 先写点dbexts, dbexts是zxJDBC作者写的一个扩 ...

  4. python对象模型 ruby_使用JRuby/Jython实现Ruby/Python的互操作性?

    不,那不行.至少不是你想的那样.在 Jython和JRuby之间的互操作性与CPython和YARV之间的工作方式相同:它们都运行在同一个平台上,因此可以使用该平台彼此通信.在 在CPython和YA ...

  5. jython在MyEclipse控制台出现Failed to install

    1.问题 在用jython在MyEclipse中开发的时候,控制台的输出出现如下错误: console: Failed to install ": java.nio.charset.Unsu ...

  6. python和c-Cpython和Jython的对比介绍

    CPython 当我们从Python官方网站下载并安装好Python 3.x后,我们就直接获得了一个官方版本的解释器:CPython.这个解释器是用C语言开发的,所以叫CPython.在命令行下运行p ...

  7. Python与Java之间的相互调用——Jython

    概述: Jython 是一种可以把两种不同的编程语言结合在一起的工具.首先,它使Python 程序员介入到Java 开发环境并让他们能快速开发方案原型,以便无缝地集成到现有的Java 平台上.其次,它 ...

  8. MonkeyRunner在Windows下的Eclipse开发环境搭建步骤(兼解决网上Jython配置出错的问题)...

    网上有一篇shangdong_chu网友写的文章介绍如何在Eclipse上配置MonkeyRunner,做了挺好的一个描述,但经过我的试验在我的环境上碰到了Jython解析器出错的问题,且该文章缺少P ...

  9. Python, CPython, Pypy, Jython的简单介绍

    简单地说,Python是一门编程语言,任何一种编程语言都需要用另一种语言来实现它,比如C语言就是用机器语言来实现的.所以,Python根据实现方式不同分为了CPyhton.Pypy.Jython等. ...

最新文章

  1. VR/AR行业发展至今,它的市场规模如何
  2. 重新设计一款Android App,我会怎么做?
  3. 内存泄漏(OOM)产生原因
  4. Android 下拉式抽屉折叠动画
  5. 解决Qt graphis-view框架中,上层图元接收hover事件导致底层图元接收不到的问题
  6. jmeter上传文件搞了一天,才搞定,没高人帮忙效率就是低,赶紧记下来,以备后用...
  7. 第37课 thinkphp5添加商品基本信息及通过前置钩子上传商品主图 模型事件(勾子函数)...
  8. jQuery comet
  9. JavaEye被CSDN收购
  10. sql家庭成员、收入支出数据库
  11. 什么叫计算机硬件特征码,如何检测电脑的硬件特征码信息(主板、CPU、硬盘)...
  12. linux 做路由器系统下载文件,用Linux系统做路由器
  13. 工作室多拨宽带如何优化?
  14. 购买新款macbook pro,现在买还是等双十一?
  15. r安卡翻译成英文_WOW英文缩写翻译,新人必看!
  16. PostgreSQL修改被视图引用的表的字段
  17. 5.8晚间黄金行情走势分析及短线交易策略
  18. 时尚就是反潮流-论如何跟上技术前进的脚步
  19. 2019互联网医疗行业洞察_Web行业洞察2017
  20. 使用shell脚本下载sftp文件

热门文章

  1. python逐行读取字符串_python3.4.3下逐行读入txt文本并去重的方法
  2. mysql中的编码问题_mysql存储乱码之编码问题
  3. php限制下载文件格式,php下载文件 强制任意文件格式下载
  4. 【阿里妈妈数据科学系列】第二篇:在线分流框架下的AB Test
  5. 多线程 全局变量_python高级:6.多线程part1
  6. 福建职称计算机评聘任,职称聘任工作的有关补充规定(试行)
  7. android后台自播放音乐,Android实现后台播放音乐(Service方式)
  8. Java学习笔记_选择语句
  9. 洛谷2014 选课(树形DP)树形背包问题
  10. 数据结构-栈之二进制转十进制和八进制