gocrud - 使用圖形操作簡化結構化數據的CRUD
Go庫簡化任意深度結構化數據的創建、更新和刪除。它讓構建 REST 服務更快和簡便。
This library is built to allow these properties for the data:
- Versioning: Keep track of all edits to the data, including deletion operations.
- Authorship: Be able to track who edited (/deleted) what.
- Retention: On deletion, only mark it as deleted. Never actually delete any data. </ol>
- Cassandra
- LevelDB
- Any SQL stores (via http://golang.org/pkg/database/sql/)
- PostGreSQL (thanks philips)
- Google Datastore
- RethinkDB (thanks dancannon)
- MongoDB (thanks wolfeidau)
- Any others as requested
- 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
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
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)