Merge pull request #621 from Jimmy99/patch-12

Update 05.5.md
This commit is contained in:
astaxie
2016-04-06 16:28:55 +08:00

View File

@@ -3,7 +3,7 @@
( ***Project beedb is no longer maintained, but the code s still there*** ) ( ***Project beedb is no longer maintained, but the code s still there*** )
beedb is an ORM ( object-relational mapper ) developed in Go, by me. beedb is an ORM ( object-relational mapper ) developed in Go, by me.
It uses idiomatic Go to operate on databases, implementing struct to database mapping and acts as a lightweight Go ORM framework. The purpose of developing this ORM is not only to help people learn how to write an ORM, but also to find a good balance between functionality and performance when it comes to data persistence. It uses idiomatic Go to operate on databases, implementing struct-to-database mapping and acts as a lightweight Go ORM framework. The purpose of developing this ORM is not only to help people learn how to write an ORM, but also to find a good balance between functionality and performance when it comes to data persistence.
beedb is an open source project that supports basic ORM functionality, but doesn't support association queries. beedb is an open source project that supports basic ORM functionality, but doesn't support association queries.
@@ -45,7 +45,7 @@ Then you need to open a database connection and create a beedb object (MySQL in
} }
orm := beedb.New(db) orm := beedb.New(db)
`beedb.New()` actually has two arguments. The first is the the database object, and the second is for indicating which database engine you're using. If you're using MySQL/SQLite, you can just skip the second argument. `beedb.New()` actually has two arguments. The first is the database object, and the second is for indicating which database engine you're using. If you're using MySQL/SQLite, you can just skip the second argument.
Otherwise, this argument must be supplied. For instance, in the case of SQLServer: Otherwise, this argument must be supplied. For instance, in the case of SQLServer:
@@ -69,7 +69,7 @@ Next, we have a struct for the `Userinfo` database table that we used in previou
} }
Be aware that beedb auto-converts camelcase names to lower snake case. For example, if we have `UserInfo` as the struct name, beedb will convert it to `user_info` in the database. The same rule applies to struct field names. Be aware that beedb auto-converts camelcase names to lower snake case. For example, if we have `UserInfo` as the struct name, beedb will convert it to `user_info` in the database. The same rule applies to struct field names.
Camel
## Insert data ## Insert data
@@ -118,7 +118,7 @@ Let's continue working with the above example to see how to update data. Now tha
saveone.Created = time.Now() saveone.Created = time.Now()
orm.Save(&saveone) // update orm.Save(&saveone) // update
Like before, you can use map for updating data also: Like before, you can also use map for updating data:
t := make(map[string]interface{}) t := make(map[string]interface{})
t["username"] = "astaxie" t["username"] = "astaxie"
@@ -148,13 +148,13 @@ Example 2:
Example 3, other query conditions: Example 3, other query conditions:
var user3 Userinfo var user3 Userinfo
// Where accepts two arguments, supports char type. // Where two arguments are accepted, with support for char type.
orm.Where("name = ?", "john").Find(&user3) orm.Where("name = ?", "john").Find(&user3)
Example 4, more complex conditions: Example 4, more complex conditions:
var user4 Userinfo var user4 Userinfo
// Where accepts three arguments // Where three arguments are accepted
orm.Where("name = ? and age < ?", "john", 88).Find(&user4) orm.Where("name = ? and age < ?", "john", 88).Find(&user4)
Examples to get multiple records: Examples to get multiple records:
@@ -229,7 +229,7 @@ beedb also has an implementation of `group by` and `having`.
## Future ## Future
I have received a lot of feedback on beedb from many people all around world, and I'm thinking about reconfiguring the following aspects: I have received a lot of feedback on beedb from many people all around the world, and I'm thinking about reconfiguring the following aspects:
- Implement an interface design similar to `database/sql/driver` in order to facilitate CRUD operations. - Implement an interface design similar to `database/sql/driver` in order to facilitate CRUD operations.
- Implement relational database associations like one to one, one to many and many to many. Here's a sample: - Implement relational database associations like one to one, one to many and many to many. Here's a sample: