Skip to content
GeorgeNava edited this page Jul 6, 2011 · 3 revisions

Datastore Manager

The datastore manager is just a layer on top of appengine datastore to make our lives easier. No need to create a context everytime you want to interact with it, or deal with cryptic errors, just fire and forget, everything should work as intended.

Here is its functionality:

    // customer.created = db.Now()
    db.Now() int64

    // customer.id = db.Sequence()
    db.Sequence() string

    // customer.key = db.NewKey("Customer")
    db.NewKey(kind string) *datastore.Key

    // customer.keyname = db.KeyName("Customer","ALFKI")
    db.KeyName(kind string, id string) *datastore.Key

    // qry := db.Query("Customer").Order("-Date").Limit(10)
    db.Query(entity string) *datastore.Query

    // db.Select(qry,&customers)
    db.Select(qry *datastore.Query, recs interface{}) bool

    // keys,ok := db.SelectKeys(qry)
    db.SelectKeys(qry *datastore.Query) ([]string, bool)

    // ok := db.Get("ALFKI",&customer)
    db.Get(id string, rec interface{}) bool

    // ok := db.GetByKey(key, &customer)
    db.GetByKey(key *datastore.Key, rec interface{}) bool

    // ok := db.New(&customer)
    db.New(rec interface{}) bool

    // ok := db.Put("ALFKI",&customer)
    db.Put(id string, rec interface{}) bool

    // ok := db.PutByKey(key, &customer)
    db.PutByKey(key *datastore.Key, rec interface{}) bool

    // ok := db.Delete("Customer","ALFKI")
    db.Delete(kind string, id string) bool

    // ok := db.DeleteByKey(key)
    db.DeleteByKey(key *datastore.Key) bool

As you can see, there is no easier way to access the datastore with simple and powerful commands that will keep your code cleaner.

Clone this wiki locally