日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

jython mysql_Jython

發布時間:2023/12/13 数据库 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jython mysql_Jython 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。