Documentation
¶
Overview ¶
Package datastore provides a flexible data storage abstraction that supports both local development (in-memory) and production (Google Cloud Datastore).
Index ¶
- type BaseEntity
- type CloudRepository
- func (r *CloudRepository) Delete(ctx context.Context, kind string, key string) error
- func (r *CloudRepository) Get(ctx context.Context, kind string, key string, dest interface{}) error
- func (r *CloudRepository) Put(ctx context.Context, kind string, key string, src interface{}) error
- func (r *CloudRepository) Query(ctx context.Context, query Query) ([]interface{}, error)
- func (r *CloudRepository) Transaction(ctx context.Context, fn func(tx Transaction) error) error
- type Filter
- type LocalRepository
- func (r *LocalRepository) Delete(ctx context.Context, kind string, key string) error
- func (r *LocalRepository) Get(ctx context.Context, kind string, key string, dest interface{}) error
- func (r *LocalRepository) Put(ctx context.Context, kind string, key string, src interface{}) error
- func (r *LocalRepository) Query(ctx context.Context, query Query) ([]interface{}, error)
- func (r *LocalRepository) Transaction(ctx context.Context, fn func(tx Transaction) error) error
- type Order
- type Query
- type Repository
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseEntity ¶
type BaseEntity struct {
CreatedAt time.Time `datastore:"created_at"`
UpdatedAt time.Time `datastore:"updated_at"`
Version int `datastore:"version"`
}
BaseEntity provides common fields for all entities
func (*BaseEntity) BeforeSave ¶
func (e *BaseEntity) BeforeSave()
BeforeSave is called before saving an entity
type CloudRepository ¶
type CloudRepository struct {
// contains filtered or unexported fields
}
CloudRepository implements Repository using Google Cloud Datastore
func NewCloudRepository ¶
func NewCloudRepository(ctx context.Context) (*CloudRepository, error)
NewCloudRepository creates a new cloud-based repository
func (*CloudRepository) Query ¶
func (r *CloudRepository) Query(ctx context.Context, query Query) ([]interface{}, error)
Query executes a query on cloud datastore
func (*CloudRepository) Transaction ¶
func (r *CloudRepository) Transaction(ctx context.Context, fn func(tx Transaction) error) error
Transaction executes operations in a cloud datastore transaction
type LocalRepository ¶
type LocalRepository struct {
// contains filtered or unexported fields
}
LocalRepository implements Repository using in-memory storage for development
func NewLocalRepository ¶
func NewLocalRepository() *LocalRepository
NewLocalRepository creates a new local in-memory repository
func (*LocalRepository) Query ¶
func (r *LocalRepository) Query(ctx context.Context, query Query) ([]interface{}, error)
Query executes a query on local storage
func (*LocalRepository) Transaction ¶
func (r *LocalRepository) Transaction(ctx context.Context, fn func(tx Transaction) error) error
Transaction executes operations in a local transaction (simplified)
type Repository ¶
type Repository interface {
// Get retrieves an entity by key
Get(ctx context.Context, kind string, key string, dest interface{}) error
// Put saves an entity with the given key
Put(ctx context.Context, kind string, key string, src interface{}) error
// Delete removes an entity by key
Delete(ctx context.Context, kind string, key string) error
// Query executes a query and returns results
Query(ctx context.Context, query Query) ([]interface{}, error)
// Transaction executes operations in a transaction
Transaction(ctx context.Context, fn func(tx Transaction) error) error
}
Repository defines the generic repository interface for entity operations
func NewRepository ¶
func NewRepository(ctx context.Context) (Repository, error)
NewRepository creates a new repository based on the environment