Documentation
¶
Overview ¶
Package yuruidb provides JSON-typed, multi-collection record storage. Import a driver to register it, call Open, and Bind each data type.
Index ¶
- Variables
- func DecodeConfig[T any](input any) (T, error)
- func Drivers() []string
- func NewID() (string, error)
- func NewRevision() (string, error)
- func OutcomeUnknown(cause error) error
- func Register(name string, factory Factory)
- func ValidateCollection(name string) error
- func ValidateID(id string) error
- type Capabilities
- type CollectionOpener
- type Config
- type Factory
- type ListOptions
- type MutationError
- type Page
- type RawPage
- type RawRecord
- type RawStore
- type Record
- type Store
- func (s *Store) Backup(ctx context.Context, w io.Writer) error
- func (s *Store) Bind[T any](collection string) error
- func (s *Store) Capabilities() Capabilities
- func (s *Store) Close() error
- func (s *Store) Delete[T any](ctx context.Context, id, revision string) error
- func (s *Store) Get[T any](ctx context.Context, id string) (Record[T], error)
- func (s *Store) Insert[T any](ctx context.Context, id string, data T) (Record[T], error)
- func (s *Store) List[T any](ctx context.Context, options ListOptions) (Page[T], error)
- func (s *Store) PurgeTombstones[T any](ctx context.Context) (int, error)
- func (s *Store) Remove[T any](ctx context.Context, id string) error
- func (s *Store) Set[T any](ctx context.Context, id string, data T) (Record[T], error)
- func (s *Store) Update[T any](ctx context.Context, id string, data T, revision string) (Record[T], error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("yuruidb: record not found") ErrAlreadyExists = errors.New("yuruidb: record already exists") ErrConflict = errors.New("yuruidb: revision conflict") ErrUnsupported = errors.New("yuruidb: unsupported capability") ErrInvalid = errors.New("yuruidb: invalid argument") ErrClosed = errors.New("yuruidb: store closed") // ErrOutcomeUnknown means a remote mutation may have committed. Do not retry // with a different ID or revision without reconciling the outcome. // Built-in drivers exclude ErrConflict/ErrAlreadyExists from unknown outcomes. ErrOutcomeUnknown = errors.New("yuruidb: mutation outcome unknown") )
Functions ¶
func DecodeConfig ¶
DecodeConfig helps statically imported third-party factories accept either their own configuration type or a driver-neutral Config/map. Unknown fields are rejected. It performs no I/O or environment lookup.
func NewID ¶
NewID creates an RFC 9562 UUIDv7. IDs are monotonic within this process even if its wall clock moves backward. Independent processes are not coordinated.
func NewRevision ¶
func OutcomeUnknown ¶
OutcomeUnknown preserves diagnostic causes while excluding definitive conflict and duplicate classifications. A retry's failed condition cannot establish whether an earlier request committed. Other Is/As queries still reach cause.
func ValidateCollection ¶
ValidateCollection accepts a portable, single-component collection name.
func ValidateID ¶
ValidateID accepts a portable ASCII name of 1..256 bytes. Slash and URL metacharacters are excluded. IDs retain case and are ordered bytewise.
Types ¶
type Capabilities ¶
Capabilities describes guarantees, independently of driver availability.
type CollectionOpener ¶
CollectionOpener supplies borrowed collection views. Their lifetime is owned by the root RawStore; closing a view must not close the shared connection.
type Config ¶
Config is the driver-neutral configuration path for applications that import only backends and choose drivers through build tags. Keys are the fields of the selected driver's Config, case-insensitively. Typed constructors and typed driver Config values remain available for direct imports. Function and client values can be supplied without serializing credentials or callbacks.
type ListOptions ¶
type MutationError ¶
type MutationError struct {
Operation, Collection, ID, Nonce, ExpectedRevision, AttemptedRevision string
Cause error
}
MutationError preserves the identity of an attempted mutation for later reconciliation. Nonce is stored in the envelope; AttemptedRevision may omit a native token when the response was lost. Unwrap preserves diagnostic Is/As queries except definitive ErrConflict and ErrAlreadyExists classifications.
func (*MutationError) Error ¶
func (e *MutationError) Error() string
func (*MutationError) MatchesRevision ¶
func (e *MutationError) MatchesRevision(value string) bool
MatchesRevision reports whether a retrieved revision identifies this exact attempted write, ignoring a native token unavailable after response loss. False does not prove failure: the write may have been superseded or deleted.
func (*MutationError) Unwrap ¶
func (e *MutationError) Unwrap() error
type RawRecord ¶
RawRecord is the byte-oriented driver record. Value contains caller-owned bytes. ID is immutable; Revision is an opaque concurrency token.
type RawStore ¶
type RawStore interface {
Insert(context.Context, string, []byte) (RawRecord, error)
Get(context.Context, string) (RawRecord, error)
List(context.Context, ListOptions) (RawPage, error)
Update(context.Context, string, []byte, string) (RawRecord, error)
Delete(context.Context, string, string) error
Capabilities() Capabilities
Close() error
}
RawStore is the byte-oriented contract implemented by drivers. Values are opaque bytes at this layer; Store handles JSON encoding. Each store is bound to one collection. List traverses immutable IDs in ascending byte order, without page snapshots. Update and Delete require a previously retrieved revision.
type Record ¶
type Record[T any] struct { Data T // contains filtered or unexported fields }
Record holds JSON data and read-only storage metadata. Modify Data and pass it to Update with ID() and Revision(); the returned record has a new revision.
func (Record[T]) MarshalJSON ¶
MarshalJSON includes metadata as id and revision alongside data.
func (Record[T]) Revision ¶
Revision returns the opaque concurrency token for this retrieved version. Updating storage returns a new Record without modifying the original value.
func (*Record[T]) UnmarshalJSON ¶
UnmarshalJSON replaces the complete record, restoring metadata from JSON. A decoding error leaves the existing record unchanged.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store owns a backend connection and binds distinct Go types to collections. Its generic methods encode JSON; Record[T] retains the requested data type. List uses ascending ID byte order and does not provide page snapshots.
func Open ¶
Open opens one backend. Omit Collection in driver options and call Bind for each data type. Driver constructors expose the same connection-scoped API.
func Wrap ¶
Wrap gives ownership of a raw backend to a JSON store. Bind each type before use. A third-party raw backend without OpenCollection can bind one collection.
func (*Store) Backup ¶
Backup writes a consistent snapshot of the entire backend, including all collections. Currently supported by bbolt. The caller owns and closes w.
func (*Store) Bind ¶
Bind registers a stable collection name for a data type. Defined types such as type Done Job and type Waiting Job are distinct; aliases are not. Pointer and value forms resolve to the same collection. Registration does no I/O.
func (*Store) Capabilities ¶
func (s *Store) Capabilities() Capabilities
func (*Store) PurgeTombstones ¶
PurgeTombstones removes retained tombstones using conditional deletion.
func (*Store) Remove ¶
Remove unconditionally deletes an ID on drivers with explicit support for this operation, currently Cloudflare KV. Other drivers return ErrUnsupported.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapter reuses yuruidb's record, cursor and revision semantics for statically imported third-party KVS or object-storage drivers.
|
Package adapter reuses yuruidb's record, cursor and revision semantics for statically imported third-party KVS or object-storage drivers. |
|
Package auth provides injectable request authorization without cloud SDKs.
|
Package auth provides injectable request authorization without cloud SDKs. |
|
aws
Package aws signs HTTP requests with AWS Signature Version 4.
|
Package aws signs HTTP requests with AWS Signature Version 4. |
|
gcp
Package gcp provides a small cached token provider for GCP metadata servers.
|
Package gcp provides a small cached token provider for GCP metadata servers. |
|
Package backends statically imports driver groups selected by build tags.
|
Package backends statically imports driver groups selected by build tags. |
|
Package blob provides immutable streaming documents, kept in a separate collection from JSON records.
|
Package blob provides immutable streaming documents, kept in a separate collection from JSON records. |
|
drivers
|
|
|
bbolt
Package bbolt registers the local-file bbolt driver.
|
Package bbolt registers the local-file bbolt driver. |
|
cfkv
Package cfkv registers the eventually consistent Cloudflare Workers KV driver.
|
Package cfkv registers the eventually consistent Cloudflare Workers KV driver. |
|
d1
Package d1 registers Cloudflare D1 via REST SQL.
|
Package d1 registers Cloudflare D1 via REST SQL. |
|
dynamodb
Package dynamodb registers DynamoDB via the signed JSON HTTP API.
|
Package dynamodb registers DynamoDB via the signed JSON HTTP API. |
|
firebase
Package firebase registers Firebase Realtime Database through REST.
|
Package firebase registers Firebase Realtime Database through REST. |
|
firestore
Package firestore registers Cloud Firestore through its REST API.
|
Package firestore registers Cloud Firestore through its REST API. |
|
gcs
Package gcs registers Google Cloud Storage via its JSON HTTP API.
|
Package gcs registers Google Cloud Storage via its JSON HTTP API. |
|
memory
Package memory registers the in-process memory driver.
|
Package memory registers the in-process memory driver. |
|
r2
Package r2 registers Cloudflare R2 via its S3-compatible HTTP API.
|
Package r2 registers Cloudflare R2 via its S3-compatible HTTP API. |
|
s3
Package s3 registers S3 general-purpose buckets via a signed HTTP API.
|
Package s3 registers S3 general-purpose buckets via a signed HTTP API. |
|
sql
Package sql registers the "sql" driver over an injected database/sql DB.
|
Package sql registers the "sql" driver over an injected database/sql DB. |
|
examples
|
|
|
basic
command
|
|
|
drivers
command
Run with go run -tags aws ./examples/drivers to inspect the statically linked drivers.
|
Run with go run -tags aws ./examples/drivers to inspect the statically linked drivers. |
|
internal
|
|
|
conformance
Package conformance contains the shared acceptance suite used by driver tests.
|
Package conformance contains the shared acceptance suite used by driver tests. |
|
protocoltest
Package protocoltest implements independent, atomic HTTP protocol fixtures for the supported providers.
|
Package protocoltest implements independent, atomic HTTP protocol fixtures for the supported providers. |
|
recordstore
Package recordstore implements record semantics on atomic conditional stores.
|
Package recordstore implements record semantics on atomic conditional stores. |