Documentation ¶
Index ¶
- Variables
- func DocRef(db *firestore.Client, model Model) *firestore.DocumentRef
- func LoadDocAndPopulate(ctx context.Context, docRef *firestore.DocumentRef, model Model) error
- func PopulateModelFrom(model Model, doc *firestore.DocumentSnapshot) error
- type CustomModelID
- type DocumentRef
- type Model
- type ModelCustomID
- type ModelImpl
- type PrimaryData
- type ServiceData
- type StdModel
- type Storage
- func (s *Storage) DeleteModel(ctx context.Context, model Model) error
- func (s *Storage) DocRef(model Model) *DocumentRef
- func (s *Storage) FirestoreClient() *firestore.Client
- func (s *Storage) GetModel(ctx context.Context, model Model) error
- func (s *Storage) Iterate(iter *firestore.DocumentIterator, factory Model) []Model
- func (s *Storage) LoadToModel(ctx context.Context, docRef *firestore.DocumentRef, model Model) error
- func (s *Storage) UpsertIfNotExists(ctx context.Context, model Model) error
- func (s *Storage) UpsertModel(ctx context.Context, model Model) error
- type Timestamp
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func DocRef ¶
func DocRef(db *firestore.Client, model Model) *firestore.DocumentRef
DocRef returns the firestore.DocumentRef based on model.
func LoadDocAndPopulate ¶
LoadDocAndPopulate looks up firestore document by ID in the store and uses to set fields in model.
func PopulateModelFrom ¶
func PopulateModelFrom(model Model, doc *firestore.DocumentSnapshot) error
PopulateModelFrom set fields in model from firestore document.
Types ¶
type CustomModelID ¶
A helper interface for custom storage models with a custom implementation of model ID storage.
type DocumentRef ¶
type DocumentRef = firestore.DocumentRef
type Model ¶
type Model interface { // returns new empy model NewModel() Model // Exists returns true if model (after retrieving from the database) existing in database. Exists() bool ModelID() string SetModelID(in string) // CollectionName returns name of the collection (in firestore) where stored model. CollectionName() string // ModelUpdatedAt returns update datetime in the database. // if model is exists returns valid value // if the model does not exist returns empty time.Time (time.Time{}.IsZero() == true) ModelUpdatedAt() time.Time // ModelUpdatedAt returns create datetime in the database. // if model is exists returns valid value // if the model does not exist returns empty time.Time (time.Time{}.IsZero() == true) ModelCreatedAt() time.Time // contains filtered or unexported methods }
Model for custom structure with user data. It stores user data and specifies in which collection is stored. It also implements the method of creating an instance of itself.
func IterateAllDocsAndStop ¶
func IterateAllDocsAndStop(iter *firestore.DocumentIterator, kind Model) ([]Model, error)
IterateAllDocsAndStop iterate through the records and to populate in model.
type ModelCustomID ¶
type ModelCustomID struct {
ServiceData
}
type ModelImpl ¶
type ModelImpl interface { // CollectionName returns name of the collection (in firestore) where stored model. CollectionName() string NewModel() Model }
A helper interface specifying the requirements for custom storage models.
type PrimaryData ¶
type PrimaryData struct {
ID string `firestore:"-"`
}
func (*PrimaryData) ModelID ¶
func (m *PrimaryData) ModelID() string
func (*PrimaryData) SetModelID ¶
func (m *PrimaryData) SetModelID(in string)
type ServiceData ¶
type ServiceData struct {
Doc *firestore.DocumentSnapshot `firestore:"-"`
}
Implements a mandatory interface for any storage model.
func (*ServiceData) Exists ¶
func (m *ServiceData) Exists() bool
func (*ServiceData) ModelCreatedAt ¶
func (m *ServiceData) ModelCreatedAt() time.Time
func (*ServiceData) ModelUpdatedAt ¶
func (m *ServiceData) ModelUpdatedAt() time.Time
type StdModel ¶
type StdModel struct { ServiceData PrimaryData }
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
func NewStorage ¶
func (*Storage) DeleteModel ¶
DeleteModel deletes the model.
func (*Storage) DocRef ¶
func (s *Storage) DocRef(model Model) *DocumentRef
func (*Storage) FirestoreClient ¶
func (*Storage) Iterate ¶
func (s *Storage) Iterate(iter *firestore.DocumentIterator, factory Model) []Model
Iterate iterate through the records and to populate in model.
func (*Storage) LoadToModel ¶
func (s *Storage) LoadToModel(ctx context.Context, docRef *firestore.DocumentRef, model Model) error
LoadToModel looks up firestore document by ID in the store and uses to set fields in model.
func (*Storage) UpsertIfNotExists ¶
UpsertIfNotExists helper method for to perform update if the model does not exist in the storage. WARN: Model.Exsits() returns false after successfully upsert