datastore

package
v1.36.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
var DecodeKey = key.Decode
View Source
var EncodeKey = key.Encode

Export key functions

Functions

func GetKinds

func GetKinds(ctx context.Context) []string

GetKinds returns all entity kinds

func GetNamespaces

func GetNamespaces(ctx context.Context) []string

GetNamespaces returns all namespaces In the new architecture, namespaces are registered explicitly

func LoadStruct

func LoadStruct(dst interface{}, ps []Property) error

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

func SetDefaultDB(database db.DB)

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 Cursor

type Cursor = iface.Cursor

Cursor is the interface for query cursors

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

func New(ctx context.Context) *Datastore

New creates a new Datastore with the given context. Uses the default database if one was set via SetDefaultDB.

func NewWithDB

func NewWithDB(ctx context.Context, database db.DB) *Datastore

NewWithDB creates a new Datastore with a specific database

func (*Datastore) AllocateID

func (d *Datastore) AllocateID(kind string, parent Key) int64

func (*Datastore) AllocateIDs

func (d *Datastore) AllocateIDs(kind string, parent Key, n int) (int64, int64)

func (*Datastore) AllocateKey

func (d *Datastore) AllocateKey(kind string, parent Key) *key.DatastoreKey

func (*Datastore) AllocateOrphanID

func (d *Datastore) AllocateOrphanID(kind string) int64

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) DB

func (d *Datastore) DB() db.DB

DB returns the underlying database

func (*Datastore) DecodeCursor

func (d *Datastore) DecodeCursor(cursor string) (Cursor, error)

DecodeCursor decodes a cursor string

func (*Datastore) DecodeKey

func (d *Datastore) DecodeKey(encoded string) (*key.DatastoreKey, error)

Encode/decode hashid keys

func (*Datastore) Delete

func (d *Datastore) Delete(k Key) error

Delete an entity

func (*Datastore) DeleteMulti

func (d *Datastore) DeleteMulti(keys interface{}) error

func (*Datastore) EncodeKey

func (d *Datastore) EncodeKey(k Key) string

func (*Datastore) Get

func (d *Datastore) Get(k Key, value interface{}) error

Gets an entity using datastore.Key or encoded Key

func (*Datastore) GetById

func (d *Datastore) GetById(id string, value interface{}) error

Gets an entity using datastore.Key or encoded Key

func (*Datastore) GetMulti

func (d *Datastore) GetMulti(keys interface{}, vals interface{}) error

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

func (d *Datastore) GetNamespace() string

GetNamespace returns the current namespace

func (*Datastore) MustDelete

func (d *Datastore) MustDelete(k Key)

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) MustGet

func (d *Datastore) MustGet(k Key, value 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) NewKey

func (d *Datastore) NewKey(kind, stringID string, intID int64, parent Key) *key.DatastoreKey

Wrap key creation funcs

func (*Datastore) NewKeyFromId

func (d *Datastore) NewKeyFromId(id string) *key.DatastoreKey

Create helpers

func (*Datastore) NewKeyFromInt

func (d *Datastore) NewKeyFromInt(kind string, id interface{}, parent Key) (*key.DatastoreKey, error)

func (*Datastore) NewKeyFromString

func (d *Datastore) NewKeyFromString(kind string, id string, parent Key) *key.DatastoreKey

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) Query

func (d *Datastore) Query(kind string) Query

Return a *datastore.Query

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

func (d *Datastore) SetContext(ctx context.Context)

SetContext extracts the Go context from a Gin context (if applicable) and stores it.

func (*Datastore) SetDB

func (d *Datastore) SetDB(database db.DB)

SetDB sets the underlying database

func (*Datastore) SetNamespace

func (d *Datastore) SetNamespace(ns string)

Set namespace for datastore

type Key

type Key = iface.Key

Key is the interface for datastore keys

type Property

type Property struct {
	Name    string
	Value   interface{}
	NoIndex bool
	Multi   bool
}

Property represents a datastore property

func SaveStruct

func SaveStruct(src interface{}) ([]Property, error)

SaveStruct saves a struct to properties (src should be a pointer)

type PropertyList

type PropertyList []Property

PropertyList is a list of properties

type PropertyLoadSaver

type PropertyLoadSaver interface {
	Load([]Property) error
	Save() ([]Property, error)
}

PropertyLoadSaver is the interface for custom property loading/saving

type Query

type Query = iface.Query

Query is the interface for datastore queries

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL