https://github.com/aodin/manager
Totally not an ORM for Go
https://github.com/aodin/manager
Last synced: 2 months ago
JSON representation
Totally not an ORM for Go
- Host: GitHub
- URL: https://github.com/aodin/manager
- Owner: aodin
- License: mit
- Created: 2016-03-13T20:51:03.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-07T01:47:37.000Z (almost 9 years ago)
- Last Synced: 2025-01-21T08:29:43.874Z (4 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Manager
=======[](https://godoc.org/github.com/aodin/manager)
[](https://travis-ci.org/aodin/manager)Totally not an ORM for Go.
For use with the SQL toolkits [Sol](https://github.com/aodin/sol) and [Fields](https://github.com/aodin/fields).
Manager adds convenience methods such as `Get`, auto-joins, and injected conditional clauses to SQL tables.
```go
// Serial and Timestamp will be set by the database
type Item struct {
fields.Serial
Name string
IsFree bool
fields.Timestamp
}func (item Item) Error(conn sol.Conn) *errors.Error {
return nil
}func (item *Item) Save(conn sol.Conn) error {
return conn.Query(Items.Insert().Values(item).Returning(), item)
}// Create a Table and immediately wrap it in a manager. Since the TableElem
// is embedded all its methods are available
var Items = postgres.Table("items",
fields.Serial{},
sol.Column("name", types.Varchar().Limit(32).NotNull()),
sol.Column("is_free", types.Boolean().NotNull()),
sol.PrimaryKey("id"),
fields.Timestamp{},
)var ItemsManager = manager.New(Items)
func main() {
Items.Use(conn) // A connection must be setitem := NewItem("a")
Items.Save(&item) // Pass a pointer for database-level field assignments
log.Println(item.Exists())Items.Get(&item, item.ID)
}
```Extend the manager by embedding it in your own struct.
Happy Hacking!
aodin, 2016