Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
e48e1dda
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e48e1dda
编写于
9月 11, 2014
作者:
A
astaxie
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #812 from ZhengYang/develop
More SQL keywords added and code cleanup
上级
9013f5c6
1f9281c8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
22 deletion
+59
-22
orm/qb.go
orm/qb.go
+5
-0
orm/qb_mysql.go
orm/qb_mysql.go
+54
-22
未找到文件。
orm/qb.go
浏览文件 @
e48e1dda
...
...
@@ -34,6 +34,11 @@ type QueryBuilder interface {
Offset
(
offset
int
)
QueryBuilder
GroupBy
(
fields
...
string
)
QueryBuilder
Having
(
cond
string
)
QueryBuilder
Update
(
tables
...
string
)
QueryBuilder
Set
(
kv
...
string
)
QueryBuilder
Delete
(
tables
...
string
)
QueryBuilder
InsertInto
(
table
string
,
fields
...
string
)
QueryBuilder
Values
(
vals
...
string
)
QueryBuilder
Subquery
(
sub
string
,
alias
string
)
string
String
()
string
}
...
...
orm/qb_mysql.go
浏览文件 @
e48e1dda
...
...
@@ -20,95 +20,127 @@ import (
"strings"
)
const
COMMA_SPACE
=
", "
type
MySQLQueryBuilder
struct
{
Query
Tokens
[]
string
Tokens
[]
string
}
func
(
qb
*
MySQLQueryBuilder
)
Select
(
fields
...
string
)
QueryBuilder
{
segment
:=
fmt
.
Sprintf
(
"SELECT %s"
,
strings
.
Join
(
fields
,
", "
))
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
segment
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"SELECT"
,
strings
.
Join
(
fields
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
From
(
tables
...
string
)
QueryBuilder
{
segment
:=
fmt
.
Sprintf
(
"FROM %s"
,
strings
.
Join
(
tables
,
", "
))
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
segment
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"FROM"
,
strings
.
Join
(
tables
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
InnerJoin
(
table
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"INNER JOIN "
+
table
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"INNER JOIN"
,
table
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
LeftJoin
(
table
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"LEFT JOIN "
+
table
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"LEFT JOIN"
,
table
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
RightJoin
(
table
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"RIGHT JOIN "
+
table
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"RIGHT JOIN"
,
table
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
On
(
cond
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"ON "
+
cond
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"ON"
,
cond
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Where
(
cond
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"WHERE "
+
cond
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"WHERE"
,
cond
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
And
(
cond
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"AND "
+
cond
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"AND"
,
cond
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Or
(
cond
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"OR "
+
cond
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"OR"
,
cond
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
In
(
vals
...
string
)
QueryBuilder
{
segment
:=
fmt
.
Sprintf
(
"IN (%s)"
,
strings
.
Join
(
vals
,
", "
))
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
segment
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"IN"
,
"("
,
strings
.
Join
(
vals
,
COMMA_SPACE
),
")"
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
OrderBy
(
fields
...
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"ORDER BY "
+
strings
.
Join
(
fields
,
", "
))
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"ORDER BY"
,
strings
.
Join
(
fields
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Asc
()
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
Query
Tokens
,
"ASC"
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"ASC"
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Desc
()
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
Query
Tokens
,
"DESC"
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"DESC"
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Limit
(
limit
int
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"LIMIT "
+
strconv
.
Itoa
(
limit
))
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"LIMIT"
,
strconv
.
Itoa
(
limit
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Offset
(
offset
int
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"OFFSET "
+
strconv
.
Itoa
(
offset
))
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"OFFSET"
,
strconv
.
Itoa
(
offset
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
GroupBy
(
fields
...
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"GROUP BY "
+
strings
.
Join
(
fields
,
", "
))
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"GROUP BY"
,
strings
.
Join
(
fields
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Having
(
cond
string
)
QueryBuilder
{
qb
.
QueryTokens
=
append
(
qb
.
QueryTokens
,
"HAVING "
+
cond
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"HAVING"
,
cond
)
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Update
(
tables
...
string
)
QueryBuilder
{
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"UPDATE"
,
strings
.
Join
(
tables
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Set
(
kv
...
string
)
QueryBuilder
{
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"SET"
,
strings
.
Join
(
kv
,
COMMA_SPACE
))
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Delete
(
tables
...
string
)
QueryBuilder
{
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"DELETE"
)
if
len
(
tables
)
!=
0
{
qb
.
Tokens
=
append
(
qb
.
Tokens
,
strings
.
Join
(
tables
,
COMMA_SPACE
))
}
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
InsertInto
(
table
string
,
fields
...
string
)
QueryBuilder
{
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"INSERT INTO"
,
table
)
if
len
(
fields
)
!=
0
{
fieldsStr
:=
strings
.
Join
(
fields
,
COMMA_SPACE
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"("
,
fieldsStr
,
")"
)
}
return
qb
}
func
(
qb
*
MySQLQueryBuilder
)
Values
(
vals
...
string
)
QueryBuilder
{
valsStr
:=
strings
.
Join
(
vals
,
COMMA_SPACE
)
qb
.
Tokens
=
append
(
qb
.
Tokens
,
"VALUES"
,
"("
,
valsStr
,
")"
)
return
qb
}
...
...
@@ -117,5 +149,5 @@ func (qb *MySQLQueryBuilder) Subquery(sub string, alias string) string {
}
func
(
qb
*
MySQLQueryBuilder
)
String
()
string
{
return
strings
.
Join
(
qb
.
Query
Tokens
,
" "
)
return
strings
.
Join
(
qb
.
Tokens
,
" "
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录