datastore

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package datastore provides a flexible data storage abstraction that supports both local development (in-memory) and production (Google Cloud Datastore).

Index

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

func (r *CloudRepository) Delete(ctx context.Context, kind string, key string) error

Delete removes an entity from cloud datastore

func (*CloudRepository) Get

func (r *CloudRepository) Get(ctx context.Context, kind string, key string, dest interface{}) error

Get retrieves an entity from cloud datastore

func (*CloudRepository) Put

func (r *CloudRepository) Put(ctx context.Context, kind string, key string, src interface{}) error

Put saves an entity to cloud datastore

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 Filter

type Filter struct {
	Field    string
	Operator string
	Value    interface{}
}

Filter represents a query filter

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

func (r *LocalRepository) Delete(ctx context.Context, kind string, key string) error

Delete removes an entity from local storage

func (*LocalRepository) Get

func (r *LocalRepository) Get(ctx context.Context, kind string, key string, dest interface{}) error

Get retrieves an entity from local storage

func (*LocalRepository) Put

func (r *LocalRepository) Put(ctx context.Context, kind string, key string, src interface{}) error

Put saves an entity to local storage

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 Order

type Order struct {
	Field      string
	Descending bool
}

Order represents a query ordering

type Query

type Query struct {
	Kind    string
	Filters []Filter
	Orders  []Order
	Limit   int
	Offset  int
}

Query represents a datastore query

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

type Transaction

type Transaction interface {
	Get(kind string, key string, dest interface{}) error
	Put(kind string, key string, src interface{}) error
	Delete(kind string, key string) error
}

Transaction represents a transactional context

Jump to

Keyboard shortcuts

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