Documentation ¶
Overview ¶
Package db defines common database interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configured ¶
func Configured() bool
Configured returns true if there's at least one registered implementation.
func Register ¶
func Register(db Impl)
Register registers a database implementation.
Must be called during init() time.
func VisitImpls ¶
func VisitImpls(cb func(db *Impl))
VisitImpls calls the callback for all registered implementation.
Types ¶
type DB ¶
type DB interface { // Kind identifies this particular database implementation. // // Among other things it is used in Cloud Tasks messages involved in the // implementation of the distributed sweeping. Kind() string // Defer defers the execution of the callback until the transaction lands. // // Panics if called outside of a transaction. // // The callback will receive the original non-transactional context. Defer(context.Context, func(context.Context)) // SaveReminder persists reminder in a transaction context. // // Tags retriable errors as transient. SaveReminder(context.Context, *reminder.Reminder) error // DeleteReminder deletes reminder in a non-transaction context. DeleteReminder(context.Context, *reminder.Reminder) error // FetchRemindersMeta fetches Reminders with Ids in [low..high) range. // // RawPayload of Reminders should not be fetched. // Both fresh & stale reminders should be fetched. // The reminders should be returned in order of ascending Id. // // In case of error, partial result of fetched Reminders so far should be // returned alongside the error. The caller will later call this method again // to fetch the remaining of Reminders in range of [<lastReturned.Id+1> .. high). FetchRemindersMeta(ctx context.Context, low, high string, limit int) ([]*reminder.Reminder, error) // FetchReminderRawPayloads fetches raw payloads of a batch of Reminders. // // The Reminder objects are re-used in the returned batch. // If any Reminder is no longer found, it is silently omitted in the returned // batch. // In case of any other error, partial result of fetched Reminders so far // should be returned alongside the error. FetchReminderRawPayloads(context.Context, []*reminder.Reminder) ([]*reminder.Reminder, error) }
DB abstracts out specific storage implementation.
type Impl ¶
type Impl struct { // Kind identifies this particular DB implementation. // // Must match Kind() of the produced DB instance. Kind string // Module is name of the server module with DB implementation, if any. Module module.Name // ProbeForTxn "probes" a context for an active transaction, returning a DB // that can be used to transactionally submit reminders or nil if this is not // a transactional context. ProbeForTxn func(context.Context) DB // NonTxn returns an instance of DB that can be used outside of // transactions. // // This is used by the sweeper to enumerate reminders. NonTxn func(context.Context) DB }
Impl knows how to instantiate DB instances.
Click to show internal directories.
Click to hide internal directories.