Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
ad2965bb
Commit
ad2965bb
authored
Aug 07, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update docs
parent
37f8c6a0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
59 deletions
+116
-59
README.md
orm/README.md
+112
-2
README.md
orm/docs/zh/README.md
+4
-57
No files found.
orm/README.md
View file @
ad2965bb
#
#
beego orm
# beego orm
a powerful orm framework
now, beta, unstable, may be changing some api make your app build failed.
**Driver Support:**
*
MySQL:
[
github.com/go-sql-driver/mysql
](
https://github.com/go-sql-driver/mysql
)
**Features:**
...
**Install:**
go get github.com/astaxie/beego/orm
## Quick Start
#### Simple Usage
```
go
package
main
import
(
"fmt"
"github.com/astaxie/beego/orm"
_
"github.com/go-sql-driver/mysql"
// import your used driver
)
// Model Struct
type
User
struct
{
Id
int
`orm:"auto"`
Name
string
`orm:"size(100)"`
orm
.
Manager
}
func
init
()
{
// register model
orm
.
RegisterModel
(
new
(
User
))
// set default database
orm
.
RegisterDataBase
(
"default"
,
"mysql"
,
"root:root@/my_db?charset=utf8"
,
30
)
}
func
main
()
{
o
:=
orm
.
NewOrm
()
user
:=
User
{
Name
:
"slene"
}
// insert
id
,
err
:=
o
.
Insert
(
&
user
)
// update
user
.
Name
=
"astaxie"
num
,
err
:=
o
.
Update
(
&
user
)
// read one
u
:=
User
{
Id
:
user
.
Id
}
err
=
o
.
Read
(
&
u
)
// delete
num
,
err
=
o
.
Delete
(
&
u
)
}
```
#### Next with relation
```
go
type
Post
struct
{
Id
int
`orm:"auto"`
Title
string
`orm:"size(100)"`
User
*
User
`orm:"rel(fk)"`
orm
.
Manager
}
var
posts
[]
*
Post
qs
:=
o
.
QueryTable
(
"post"
)
num
,
err
:=
qs
.
Filter
(
"User__Name"
,
"slene"
)
.
All
(
&
posts
)
```
#### Use Raw sql
```
go
var
maps
[]
Params
num
,
err
:=
o
.
Raw
(
"SELECT id FROM user WHERE name = ?"
,
"slene"
)
.
Values
(
&
maps
)
if
num
>
0
{
fmt
.
Println
(
maps
[
0
][
"id"
])
}
```
#### Transaction
```
go
o
.
Begin
()
...
user
:=
User
{
Name
:
"slene"
}
id
,
err
:=
o
.
Insert
(
&
user
)
if
err
!=
nil
{
o
.
Commit
()
}
else
{
o
.
Rollback
()
}
```
## Docs
more details and examples in docs and test
*
[
中文
](
docs/zh
)
*
English
## TODO
-
some unrealized api
-
examples
-
docs
-
support postgres
-
support sqlite
-
support postgres
##
orm/docs/zh/README.md
View file @
ad2965bb
## beego orm 介绍
## 快速入门
```
go
package
main
import
(
"fmt"
"github.com/astaxie/beego/orm"
_
"github.com/go-sql-driver/mysql"
)
// 最简单的两个表的定义
type
User
struct
{
Id
int
`orm:"auto"`
Name
string
`orm:"size(100)"`
orm
.
Manager
}
func
init
()
{
// 将表定义注册到 orm 里
orm
.
RegisterModel
(
new
(
User
))
// 链接参数设置
orm
.
RegisterDataBase
(
"default"
,
"mysql"
,
"root:root@/my_db?charset=utf8"
,
30
)
}
func
main
()
{
o
:=
orm
.
NewOrm
()
user
:=
User
{
Name
:
"slene"
}
// 创建
id
,
err
:=
o
.
Insert
(
&
user
)
fmt
.
Println
(
id
,
err
)
// 更新
user
.
Name
=
"astaxie"
num
,
err
:=
o
.
Update
(
&
user
)
fmt
.
Println
(
num
,
err
)
// 查询单个
u
:=
User
{
Id
:
user
.
Id
}
err
=
o
.
Read
(
&
u
)
fmt
.
Println
(
u
.
Name
,
err
)
// 删除
num
,
err
=
o
.
Delete
(
&
u
)
fmt
.
Println
(
num
,
err
)
}
```
## 详细文档
## 文档目录
1.
[
模型定义
](
Models.md
)
-
[
支持的 Field 类型
](
Models.md#
Field
T
ype)
-
[
Field 设置参数
](
Models.md#
Field
O
ptions)
-
[
关系型 Field 设置
](
Models.md#
Relation
Field O
ptions)
-
[
支持的 Field 类型
](
Models.md#
field-t
ype
)
-
[
Field 设置参数
](
Models.md#
field-o
ptions
)
-
[
关系型 Field 设置
](
Models.md#
relation-field-o
ptions
)
2.
Custom Fields
3.
[
Orm 使用方法
](
Orm.md
)
-
[
Ormer 接口
](
Orm.md#Ormer
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment