Package db defines common database interface.



    This section is empty.


    This section is empty.


    func Kinds

    func Kinds() []string

      Kinds returns IDs of registered database implementations.

      func Register

      func Register(db Impl)

        Register registers a database implementation.

        Must be called during init() time.


        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.

          func NonTxnDB

          func NonTxnDB(ctx context.Context, id string) DB

            NonTxnDB returns a database with given ID or nil if not registered.

            func TxnDB

            func TxnDB(ctx context.Context) (db DB)

              TxnDB returns a Database that matches the context or nil.

              The process has a list of database engines registered via Register. Given a context, TxnDB examines if it carries a transaction with any of the registered DBs.

              Panics if more than one database matches the context.

              type Impl

              type Impl struct {
              	// Kind identifies this particular DB implementation.
              	// Must match Kind() of the produced DB instance.
              	Kind string
              	// 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.

                Source Files