Açıklama Yok

xormplus 657075cf99 update 9 yıl önce
docs cb5fc920a7 . 10 yıl önce
test fe399adfb0 update Query and QueryWithDateFormat function 9 yıl önce
.gitignore 52a602da39 Initial commit 10 yıl önce
LICENSE 52a602da39 Initial commit 10 yıl önce
README.md 657075cf99 update 9 yıl önce
cover.out c93a5bbd96 初始化 10 yıl önce
engine.go 858078832d serious extends bug fixed & correct logger file path 10 yıl önce
engineplus.go a293180a44 bug fixed 9 yıl önce
error.go c93a5bbd96 初始化 10 yıl önce
goracle_driver.go c93a5bbd96 初始化 10 yıl önce
helpers.go 1601c637cd bug fixed for empty struct when update 9 yıl önce
helpersplus.go 858078832d serious extends bug fixed & correct logger file path 10 yıl önce
logger.go 858078832d serious extends bug fixed & correct logger file path 10 yıl önce
lru_cacher.go c93a5bbd96 初始化 10 yıl önce
memroy_store.go c93a5bbd96 初始化 10 yıl önce
mssql_dialect.go 8bb4299b35 bug fixed 9 yıl önce
mymysql_driver.go 8bb4299b35 bug fixed 9 yıl önce
mysql_dialect.go 8bb4299b35 bug fixed 9 yıl önce
mysql_driver.go 8bb4299b35 bug fixed 9 yıl önce
oci8_driver.go 8bb4299b35 bug fixed 9 yıl önce
odbc_driver.go 8bb4299b35 bug fixed 9 yıl önce
oracle_dialect.go 8bb4299b35 bug fixed 9 yıl önce
pg_reserved.txt c93a5bbd96 初始化 10 yıl önce
postgres_dialect.go 8bb4299b35 bug fixed 9 yıl önce
pq_driver.go 8bb4299b35 bug fixed 9 yıl önce
processors.go a85984d0c5 Added feature for storing lastSQL query on session 10 yıl önce
rows.go a85984d0c5 Added feature for storing lastSQL query on session 10 yıl önce
session.go ada83a1829 Support pointers to type aliases 9 yıl önce
sessionplus.go fe399adfb0 update Query and QueryWithDateFormat function 9 yıl önce
sqlite3_dialect.go 858078832d serious extends bug fixed & correct logger file path 10 yıl önce
sqlite3_driver.go c93a5bbd96 初始化 10 yıl önce
sqlmap.go 9f264f3857 sqlmap和sqltemplate的根目录除可在配置文件配置,也可以在程序初始化之前代码指定,代码指定优先级高于配置 10 yıl önce
sqltemplate.go 9f264f3857 sqlmap和sqltemplate的根目录除可在配置文件配置,也可以在程序初始化之前代码指定,代码指定优先级高于配置 10 yıl önce
statement.go 1601c637cd bug fixed for empty struct when update 9 yıl önce
syslogger.go 858078832d serious extends bug fixed & correct logger file path 10 yıl önce
types.go 6e437f24db some comments, refactors improvements 10 yıl önce
xorm.go 1601c637cd bug fixed for empty struct when update 9 yıl önce
xormplus.go db2466f3a7 修改SqlMap和SqlTemplate初始化方式 10 yıl önce

README.md

xorm

###优化xorm的查询API,并提供类似ibatis的配置文件及动态SQL功能,支持AcitveRecord操作

go get -u github.com/xormplus/xorm

测试用例测试结果

var err error
db, err = xorm.NewPostgreSQL("postgres://postgres:root@localhost:5432/testdb?sslmode=disable")

db.SqlMap.SqlMapRootDir="./sql/oracle" //SqlMap配置文件存根目录,可代码指定,可在配置文件中配置,代码指定优先级高于配置
db.SqlTemplate.SqlTemplateRootDir="./sql/oracle" //SqlTemplate配置文件存根目录,可代码指定,可在配置文件中配置,代码指定优先级高于配置
if err != nil {
	t.Fatal(err)
}

err = db.InitSqlMap() //初始化SqlMap配置,可选功能,如应用中无需使用SqlMap,可无需初始化
if err != nil {
	t.Fatal(err)
}
err = db.InitSqlTemplate() //初始化动态SQL模板配置,可选功能,如应用中无需使用SqlTemplate,可无需初始化
if err != nil {
	t.Fatal(err)
}

####db.InitSqlMap()过程

  • 如指定db.SqlMap.SqlMapRootDir,则err = db.InitSqlMap()按指定目录遍历SqlMapRootDir所配置的目录及其子目录下的所有xml配置文件(配置文件样例
  • 如未指定db.SqlMap.SqlMapRootDir,err = db.InitSqlMap()则读取程序所在目下的sql/xormcfg.ini配置文件(样例)中的SqlMapRootDir配置项,遍历SqlMapRootDir所配置的目录及其子目录下的所有xml配置文件(配置文件样例
  • 解析所有配置SqlMap的xml配置文件

####db.InitSqlTemplate()过程

  • 如指定db.SqlTemplate.SqlTemplateRootDir,err = db.InitSqlTemplate()按指定目录遍历SqlTemplateRootDir所配置的目录及其子目录下的所有stpl模板文件(模板文件样例
  • 如指未定db.SqlTemplate.SqlTemplateRootDir,err = db.InitSqlTemplate()则读取程序所在目下的sql/xormcfg.ini配置文件(样例)中的SqlTemplateRootDir配置项,遍历SqlTemplateRootDir所配置的目录及其子目录下的所有stpl模板文件(模板文件样例
  • 解析stpl模板文件

###支持类似这样的链式读取数据操作

sql := "select id,title,createdatetime,content from article where id = ?"
rows, err := db.Sql(sql, 2).Query().Json() //返回查询结果的json字符串
rows, err := db.Sql("sql", 2).QueryWithDateFormat("20060102").Json() //返回查询结果的json字符串,并支持格式化日期
rows, err := db.Sql("sql", 2).QueryWithDateFormat("20060102").Xml() //返回查询结果的xml字符串,并支持格式化日期

id := db.Sql(sql, 2).Query().Result[0]["id"] //返回查询结果的第一条数据的id列的值
title := db.Sql(sql, 2).Query().Result[0]["title"]
createdatetime := db.Sql(sql, 2).Query().Result[0]["createdatetime"]
content := db.Sql(sql, 2).Query().Result[0]["content"]

articles := make([]Article, 0)
xml,err := db.Where("id=?", 6).Find(&articles).Xml() //返回查询结果的xml字符串
json,err := db.Where("id=?", 6).Find(&articles).Json() //返回查询结果的json字符串

sql := "select id,title,createdatetime,content from article where id = ?id and userid=?userid"
paramMap := map[string]interface{}{"id": 6, "userid": 1} //支持参数使用map存放
rows, err := db.Sql(sql, &paramMap).Query().XmlIndent("", "  ", "article")

###支持SqlMap配置,配置文件样例

<sqlMap>
	<sql id="selectAllArticle">
		select id,title,createdatetime,content 
		from article where id in (?1,?2)
	</sql>
	<sql id="selectStudentById1">
		select * from article where id=?id
	</sql>
</sqlMap>
paramMap := map[string]interface{}{"1": 2, "2": 5} //支持参数使用map存放
rows, err := db.SqlMapClient("selectAllArticle", &paramMap).Query().Xml() //返回查询结果的xml字符串
rows, err := db.SqlMapClient("selectAllArticle", &paramMap).Query().Json() //返回查询结果的json字符串
rows, err := db.SqlMapClient("selectAllArticle", &paramMap).QueryWithDateFormat("2006/01/02").XmlIndent("", "  ", "article") //返回查询结果格式化的xml字符串,并支持格式化日期

###提供动态SQL支持,使用pongo2模板引擎 例如配置文件名:select.example.stpl

配置样例内容如下:

select id,userid,title,createdatetime,content 
from article where  
{% if count>1%}
id=?id
{% else%}
userid=?userid
{% endif %}
paramMap := map[string]interface{}{"id": 2, "userid": 3, "count": 1}
rows, err := db.SqlTemplateClient("select.example.stpl", paramMap).Query().Json()
rows, err := db.SqlTemplateClient("select.example.stpl", paramMap).QueryWithDateFormat("2006/01/02").Json()
rows, err := db.SqlTemplateClient("select.example.stpl", paramMap).QueryWithDateFormat("2006/01/02").XmlIndent("", "  ", "article")

###讨论 请加入QQ群:280360085 进行讨论。API设计相关建议可联系本人QQ:50892683