gocrud - 使用图形操作简化结构化数据的CRUD

jopen 9年前

Go库简化任意深度结构化数据的创建、更新和删除。它让构建 REST 服务更快和简便。

This library is built to allow these properties for the data:

  1. Versioning: Keep track of all edits to the data, including deletion operations.
  2. Authorship: Be able to track who edited (/deleted) what.
  3. Retention: On deletion, only mark it as deleted. Never actually delete any data.

The library makes it easy to have Parent-Child relationships, quite common in today’s CRUD operations. For e.g.

- Posts created by User (User -> Post)  - Comments on Posts (Post -> Comment)  - Likes on Posts (Post -> Like)  - Likes on Comments (Comment -> Like)

And be able to traverse these relationships and retrieve all of the children, grandchildren etc. For e.g.(User -> Post -> [(Comment -> Like), Like])

The library does this by utilizing Graph operations, but without using a Graph database. This means the library can be used to quickly build a Go backend to serve arbitrarily complex data, while still using your database of choice.

This library supports both SQL and NoSQL databases including other datastores, namely

  1. Cassandra
  2. LevelDB
  3. Any SQL stores (via http://golang.org/pkg/database/sql/)
  4. PostGreSQL (thanks philips)
  5. Google Datastore
  6. RethinkDB (thanks dancannon)
  7. MongoDB (thanks wolfeidau)
  8. Any others as requested

Note: To get all of these dependencies, rungo get github.com/manishrjain/gocrud/example/social.

In fact, it exposes a simple interface for operations requiring databases, so you can easily add your favorite database (or request for addition).

type Store interface {    Init(dbtype string, tablename string)    Commit(tablePrefix string, its []*x.Instruction) error    IsNew(tablePrefix string, subject string) bool    GetEntity(tablePrefix string, subject string) ([]x.Instruction, error)  }

The data is stored in a flat “tuple” format, to allow for horizontal scaling across machines in both SQL and NoSQL databases. Again, no data is ever deleted, to allow for log tracking all the changes.

Example Usage

Let's take a social backend as an example (based on social.go)

  • Users create posts
  • Other users like Posts
  • Other users comment on Posts
  • Other users like the comments
  • Other users comment on the comment (aka reply)
  • (Extra) Other users like the comment on the comment
  • (Extra) Other users comment on the like

项目主页:http://www.open-open.com/lib/view/home/1435497176466