Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f1e2372a
authored
2013-08-09 13:53:04 +0800
by
slene
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
orm update docs about debug log queries
1 parent
45aa0712
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
0 deletions
orm/README.md
orm/docs/zh/Orm.md
orm/docs/zh/README.md
orm/docs/zh/Transaction.md
orm/README.md
View file @
f1e2372
...
...
@@ -107,6 +107,29 @@ if err != nil {
```
#### Debug Log Queries
In development env, you can simple use
```
go
func
main
()
{
orm
.
Debug
=
true
...
```
enable log queries.
output include all queries, such as exec / prepare / transaction.
like this:
```
go
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.4
ms
]
-
[
INSERT
INTO
`user`
(
`name`
)
VALUES
(
?
)]
-
`slene`
...
```
note: not recommend use this in product env.
## Docs
more details and examples in docs and test
...
...
orm/docs/zh/Orm.md
View file @
f1e2372
...
...
@@ -198,3 +198,46 @@ fmt.Println(dr.Name() == "db2") // true
fmt
.
Println
(
dr
.
Type
()
==
orm
.
DR_Sqlite
)
// true
```
## 调试模式打印查询语句
简单的设置 Debug 为 true 打印查询的语句
可能存在性能问题,不建议使用在产品模式
```
go
func
main
()
{
orm
.
Debug
=
true
...
```
默认使用 os.Stderr 输出日志信息
改变输出到你自己的 io.Writer
```
go
var
w
io
.
Writer
...
// 设置为你的 io.Writer
...
orm
.
DebugLog
=
orm
.
NewLog
(
w
)
```
日志格式
```
go
[
ORM
]
-
时间
-
[
Queries
/
数据库名
]
-
[
执行操作
/
执行时间
]
-
[
SQL语句
]
-
使用标点
`,`
分隔的参数列表
-
打印遇到的错误
```
```
go
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.4
ms
]
-
[
INSERT
INTO
`user`
(
`name`
)
VALUES
(
?
)]
-
`slene`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.5
ms
]
-
[
UPDATE
`user`
SET
`name`
=
?
WHERE
`id`
=
?
]
-
`astaxie`
,
`14`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
QueryRow
/
0.4
ms
]
-
[
SELECT
`id`
,
`name`
FROM
`user`
WHERE
`id`
=
?
]
-
`14`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.4
ms
]
-
[
INSERT
INTO
`post`
(
`user_id`
,
`title`
,
`content`
)
VALUES
(
?
,
?
,
?
)]
-
`14`
,
`beego orm`
,
`powerful amazing`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Query
/
0.4
ms
]
-
[
SELECT
T1
.
`name`
`User__Name`
,
T0
.
`user_id`
`User`
,
T1
.
`id`
`User__Id`
FROM
`post`
T0
INNER
JOIN
`user`
T1
ON
T1
.
`id`
=
T0
.
`user_id`
WHERE
T0
.
`id`
=
?
LIMIT
1000
]
-
`68`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.4
ms
]
-
[
DELETE
FROM
`user`
WHERE
`id`
=
?
]
-
`14`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Query
/
0.3
ms
]
-
[
SELECT
T0
.
`id`
FROM
`post`
T0
WHERE
T0
.
`user_id`
IN
(
?
)
]
-
`14`
[
ORM
]
-
2013
-
08
-
09
13
:
18
:
16
-
[
Queries
/
default
]
-
[
db
.
Exec
/
0.4
ms
]
-
[
DELETE
FROM
`post`
WHERE
`id`
IN
(
?
)]
-
`68`
```
日志内容包括
**所有的数据库操作**
,事务,Prepare,等
...
...
orm/docs/zh/README.md
View file @
f1e2372
...
...
@@ -4,6 +4,7 @@
1.
[
Orm 使用方法
](
Orm.md
)
-
[
数据库的设置
](
Orm.md#数据库的设置
)
-
[
ORM 接口使用
](
Orm.md#orm-接口使用
)
-
[
调试模式打印查询语句
](
Orm.md#调试模式打印查询语句
)
2.
[
对象的CRUD操作
](
Object.md
)
3.
[
高级查询
](
Query.md
)
-
[
使用的表达式语法
](
Query.md#expr
)
...
...
orm/docs/zh/Transaction.md
View file @
f1e2372
## 事务处理
orm 可以简单的进行事务操作
```
go
o
:=
NewOrm
()
err
:=
o
.
Begin
()
// 事务处理过程
...
...
// 此过程中的所有使用 o Ormer 对象的查询都在事务处理范围内
if
SomeError
{
err
=
o
.
Rollback
()
}
else
{
err
=
o
.
Commit
()
}
```
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment