Documentation ¶
Index ¶
- type Base
- func (d *Base) BeforeSoftDelete()
- func (d *Base) BeforeUpdate()
- func (d *Base) CanSave() bool
- func (d *Base) FormatDate(dt time.Time, layout string) string
- func (d *Base) FormatDateShort(dt time.Time) string
- func (d *Base) FormatDateTimeShort(dt time.Time) string
- func (d *Base) GetAllTimeStamps() map[string]formattedTimestamp
- func (d *Base) GetCreatedAt() time.Time
- func (d *Base) GetFormattedCreatedAt() *formattedTimestamp
- func (d *Base) GetFormattedDeletedAt() *formattedTimestamp
- func (d *Base) GetFormattedUpdatedAt() *formattedTimestamp
- func (d *Base) GetID() primitive.ObjectID
- func (d *Base) GetTimeStamps() map[string]formattedTimestamp
- func (d *Base) GetUpdatedAt() time.Time
- func (d *Base) IsNew() bool
- func (d *Base) SetIsNew(status bool)
- func (d *Base) Setup() error
- type Document
- type PostCreator
- type PostFindOne
- type PostHardDeleter
- type PostSoftDeleter
- type PostUpdater
- type PreCreator
- type PreFindOne
- type PreHardDeleter
- type PreSoftDeleter
- type PreUpdater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"_id"` CreatedAt time.Time `bson:"created_at" json:"-"` UpdatedAt time.Time `bson:"updated_at" json:"-"` DeletedAt time.Time `bson:"deleted_at,omitempty" json:"-"` IsDeleted bool `bson:"is_deleted" json:"-"` Timestamps map[string]formattedTimestamp `bson:"-" json:"timestamps"` // contains filtered or unexported fields }
Base is the base document all documents must inherit. This ensure shared document properties can be set.
func (*Base) BeforeSoftDelete ¶
func (d *Base) BeforeSoftDelete()
func (*Base) BeforeUpdate ¶
func (d *Base) BeforeUpdate()
func (*Base) FormatDate ¶
FormatDate returns a formatted time object based on the provided layout.
func (*Base) FormatDateShort ¶
FormatDateShort returns a formatted time object in the format MMM DD, YYYY
func (*Base) FormatDateTimeShort ¶
FormatDateTimeShort returns a formatted time object in the format MMM DD, YYYY - HH:MM
func (*Base) GetAllTimeStamps ¶
func (*Base) GetCreatedAt ¶
GetCreatedAt returns a document's created time
func (*Base) GetFormattedCreatedAt ¶
func (d *Base) GetFormattedCreatedAt() *formattedTimestamp
func (*Base) GetFormattedDeletedAt ¶
func (d *Base) GetFormattedDeletedAt() *formattedTimestamp
func (*Base) GetFormattedUpdatedAt ¶
func (d *Base) GetFormattedUpdatedAt() *formattedTimestamp
func (*Base) GetTimeStamps ¶
func (*Base) GetUpdatedAt ¶
GetUpdatedAt returns a document's last update time
func (*Base) SetIsNew ¶
SetIsNew sets the isNew property to provided status. If status is true, This signals that the current instance has not been saved before and document.Save() will perform an insert. If status is false, This makes all calls to document.Save() perform an update operation not an insert.
type Document ¶
type Document interface { Setup() error CanSave() bool BeforeUpdate() BeforeSoftDelete() GetID() primitive.ObjectID GetCreatedAt() time.Time GetUpdatedAt() time.Time SetIsNew(status bool) IsNew() bool FormatDate(d time.Time, layout string) string FormatDateShort(d time.Time) string FormatDateTimeShort(d time.Time) string GetTimeStamps() map[string]formattedTimestamp GetAllTimeStamps() map[string]formattedTimestamp GetFormattedCreatedAt() *formattedTimestamp GetFormattedUpdatedAt() *formattedTimestamp GetFormattedDeletedAt() *formattedTimestamp }
Document is the base interface for all Documents. This helps all document to be initialized using a single Function.
type PostCreator ¶
type PostCreator interface { // PostCreate runs the concrete implementation after a new document is saved successfully. PostCreate(dbConnection *mongo.Database) error }
PostCreator
type PostFindOne ¶ added in v0.0.6
type PostFindOne interface { //PostFindOne runs the concrete implementation after any FindOne*() is called PostFindOne(dbConnection *mongo.Database) error }
PostFindOne - Runs after a document is successfully found and marshalled into a target
type PostHardDeleter ¶
type PostHardDeleter interface { // PostHardDelete runs the concrete implementation after a document is hard deleted. PostHardDelete(dbConnection *mongo.Database) error }
PostHardDeleter
type PostSoftDeleter ¶
type PostSoftDeleter interface { // PostSoftDelete runs the concrete implementation after a document is soft deleted. PostSoftDelete(dbConnection *mongo.Database) error }
PostSoftDeleter
type PostUpdater ¶
type PostUpdater interface { // PostUpdate runs the concrete implementation after an existing document is updated successfully. PostUpdate(dbConnection *mongo.Database) error }
PostUpdater
type PreCreator ¶
type PreCreator interface { // PreCreate runs the concrete implementation before a new document is saved. PreCreate(dbConnection *mongo.Database) error }
PreCreator Interface
type PreFindOne ¶ added in v0.0.6
type PreFindOne interface { //PreFindOne runs the concrete implementation before any FindOne*() is called PreFindOne(dbConnection *mongo.Database) error }
PreFindOne
type PreHardDeleter ¶
type PreHardDeleter interface { // PreHardDelete runs the concrete implementation before a document is hard deleted. PreHardDelete(dbConnection *mongo.Database) error }
PreHardDeleter
type PreSoftDeleter ¶
type PreSoftDeleter interface { // PreSoftDelete runs the concrete implementation before a document is soft deleted. PreSoftDelete(dbConnection *mongo.Database) error }
PreSoftDeleter
type PreUpdater ¶
type PreUpdater interface { // PreUpdate runs the concrete implementation before an existing document updated is saved. PreUpdate(dbConnection *mongo.Database) error }
PreUpdater