Documentation
¶
Index ¶
- Variables
- func GetKinds(ctx context.Context) []string
- func GetNamespaces(ctx context.Context) []string
- func LoadStruct(dst interface{}, ps []Property) error
- func RegisterNamespace(ns string)
- func RunInTransaction(ctx context.Context, fn func(db *Datastore) error, opts *TransactionOptions) error
- func SetDefaultDB(database db.DB)
- type Cursor
- type Datastore
- func (d *Datastore) AllocateID(kind string, parent Key) int64
- func (d *Datastore) AllocateIDs(kind string, parent Key, n int) (int64, int64)
- func (d *Datastore) AllocateKey(kind string, parent Key) *key.DatastoreKey
- func (d *Datastore) AllocateOrphanID(kind string) int64
- func (d *Datastore) AllocateOrphanKey(kind string, parent Key) *key.DatastoreKey
- func (d *Datastore) DB() db.DB
- func (d *Datastore) DecodeCursor(cursor string) (Cursor, error)
- func (d *Datastore) DecodeKey(encoded string) (*key.DatastoreKey, error)
- func (d *Datastore) Delete(k Key) error
- func (d *Datastore) DeleteMulti(keys interface{}) error
- func (d *Datastore) EncodeKey(k Key) string
- func (d *Datastore) Get(k Key, value interface{}) error
- func (d *Datastore) GetById(id string, value interface{}) error
- func (d *Datastore) GetMulti(keys interface{}, vals interface{}) error
- func (d *Datastore) GetNamespace() string
- func (d *Datastore) MustDelete(k Key)
- func (d *Datastore) MustDeleteMulti(keys interface{})
- func (d *Datastore) MustGet(k Key, value interface{})
- func (d *Datastore) MustGetMulti(keys interface{}, vals interface{})
- func (d *Datastore) MustPut(keyOrKind interface{}, value interface{}) *key.DatastoreKey
- func (d *Datastore) MustPutMulti(keys interface{}, vals interface{}) []*key.DatastoreKey
- func (d *Datastore) NewIncompleteKey(kind string, parent Key) *key.DatastoreKey
- func (d *Datastore) NewKey(kind, stringID string, intID int64, parent Key) *key.DatastoreKey
- func (d *Datastore) NewKeyFromId(id string) *key.DatastoreKey
- func (d *Datastore) NewKeyFromInt(kind string, id interface{}, parent Key) (*key.DatastoreKey, error)
- func (d *Datastore) NewKeyFromString(kind string, id string, parent Key) *key.DatastoreKey
- func (d *Datastore) Put(keyOrKind interface{}, val interface{}) (*key.DatastoreKey, error)
- func (d *Datastore) PutMulti(keys interface{}, vals interface{}) ([]*key.DatastoreKey, error)
- func (d *Datastore) Query(kind string) Query
- func (d *Datastore) RunInTransaction(fn func(db *Datastore) error, opts *TransactionOptions) error
- func (d *Datastore) SetContext(ctx context.Context)
- func (d *Datastore) SetDB(database db.DB)
- func (d *Datastore) SetNamespace(ns string)
- type Key
- type Property
- type PropertyList
- type PropertyLoadSaver
- type Query
- type TransactionOptions
Constants ¶
This section is empty.
Variables ¶
var ( // Done signals end of iteration Done = errors.New("datastore: done") // Standard errors - aliased from db package for compatibility ErrNoSuchEntity = db.ErrNoSuchEntity ErrInvalidEntityType = db.ErrInvalidEntityType ErrInvalidKey = db.ErrInvalidKey ErrConcurrentTransaction = db.ErrConcurrentModification // Alias utils IgnoreFieldMismatch = utils.IgnoreFieldMismatch )
var DecodeKey = key.Decode
var EncodeKey = key.Encode
Export key functions
Functions ¶
func GetNamespaces ¶
GetNamespaces returns all namespaces In the new architecture, namespaces are registered explicitly
func LoadStruct ¶
LoadStruct loads properties into a struct (dst should be a pointer)
func RegisterNamespace ¶
func RegisterNamespace(ns string)
RegisterNamespace registers a namespace for use
func RunInTransaction ¶
func RunInTransaction(ctx context.Context, fn func(db *Datastore) error, opts *TransactionOptions) error
RunInTransaction runs a function within a transaction
func SetDefaultDB ¶
SetDefaultDB sets the global default database used by New() when no explicit db.DB is provided. Call this during application bootstrap after initializing the database manager.
Types ¶
type Datastore ¶
type Datastore struct {
Context context.Context
IgnoreFieldMismatch bool
Warn bool
// contains filtered or unexported fields
}
Datastore wraps the db.DB interface to provide the legacy API
func New ¶
New creates a new Datastore with the given context. Uses the default database if one was set via SetDefaultDB.
func (*Datastore) AllocateIDs ¶
func (*Datastore) AllocateKey ¶
func (d *Datastore) AllocateKey(kind string, parent Key) *key.DatastoreKey
func (*Datastore) AllocateOrphanID ¶
Datastore uses a key's ancestry to allocate unique integer IDs. If you allocate an ID with a nil parent you get an "orphaned" ID, i.e., an ID which does not use ancestry to determine uniqueness. We have historically depended on this behavior for cheap, monotonically increasing order numbers (which are calculated from the key's integer id component).
func (*Datastore) AllocateOrphanKey ¶
func (d *Datastore) AllocateOrphanKey(kind string, parent Key) *key.DatastoreKey
func (*Datastore) DecodeCursor ¶
DecodeCursor decodes a cursor string
func (*Datastore) DecodeKey ¶
func (d *Datastore) DecodeKey(encoded string) (*key.DatastoreKey, error)
Encode/decode hashid keys
func (*Datastore) DeleteMulti ¶
func (*Datastore) GetMulti ¶
Same as Get, but works for multiple key/vals, keys can be slice of any type accepted by GetMulti as well as *[]*Model, which will automatically allocated if necessary.
func (*Datastore) GetNamespace ¶
GetNamespace returns the current namespace
func (*Datastore) MustDelete ¶
Gets an entity using datastore.Key or encoded Key
func (*Datastore) MustDeleteMulti ¶
func (d *Datastore) MustDeleteMulti(keys interface{})
Gets an entity using datastore.Key or encoded Key
func (*Datastore) MustGetMulti ¶
func (d *Datastore) MustGetMulti(keys interface{}, vals interface{})
Gets an entity using datastore.Key or encoded Key
func (*Datastore) MustPut ¶
func (d *Datastore) MustPut(keyOrKind interface{}, value interface{}) *key.DatastoreKey
Gets an entity using datastore.Key or encoded Key
func (*Datastore) MustPutMulti ¶
func (d *Datastore) MustPutMulti(keys interface{}, vals interface{}) []*key.DatastoreKey
Gets an entity using datastore.Key or encoded Key
func (*Datastore) NewIncompleteKey ¶
func (d *Datastore) NewIncompleteKey(kind string, parent Key) *key.DatastoreKey
func (*Datastore) NewKeyFromId ¶
func (d *Datastore) NewKeyFromId(id string) *key.DatastoreKey
Create helpers
func (*Datastore) NewKeyFromInt ¶
func (*Datastore) NewKeyFromString ¶
func (*Datastore) Put ¶
func (d *Datastore) Put(keyOrKind interface{}, val interface{}) (*key.DatastoreKey, error)
Puts entity using provided key or kind
func (*Datastore) PutMulti ¶
func (d *Datastore) PutMulti(keys interface{}, vals interface{}) ([]*key.DatastoreKey, error)
Keys may be either either []datastore.Key or []*key.DatastoreKey, vals expected in typical format
func (*Datastore) RunInTransaction ¶
func (d *Datastore) RunInTransaction(fn func(db *Datastore) error, opts *TransactionOptions) error
RunInTransaction runs a function within a transaction
func (*Datastore) SetContext ¶
SetContext extracts the Go context from a Gin context (if applicable) and stores it.
func (*Datastore) SetNamespace ¶
Set namespace for datastore
type Property ¶
Property represents a datastore property
func SaveStruct ¶
SaveStruct saves a struct to properties (src should be a pointer)
type PropertyLoadSaver ¶
PropertyLoadSaver is the interface for custom property loading/saving
type TransactionOptions ¶
type TransactionOptions struct {
// XG enables cross-group transactions (legacy compat, ignored in new db)
XG bool
// Attempts specifies how many retries on conflict
Attempts int
// ReadOnly indicates this is a read-only transaction
ReadOnly bool
}
TransactionOptions configures transaction behavior