document

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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) CanSave

func (d *Base) CanSave() bool

func (*Base) FormatDate

func (d *Base) FormatDate(dt time.Time, layout string) string

FormatDate returns a formatted time object based on the provided layout.

func (*Base) FormatDateShort

func (d *Base) FormatDateShort(dt time.Time) string

FormatDateShort returns a formatted time object in the format MMM DD, YYYY

func (*Base) FormatDateTimeShort

func (d *Base) FormatDateTimeShort(dt time.Time) string

FormatDateTimeShort returns a formatted time object in the format MMM DD, YYYY - HH:MM

func (*Base) GetAllTimeStamps

func (d *Base) GetAllTimeStamps() map[string]formattedTimestamp

func (*Base) GetCreatedAt

func (d *Base) GetCreatedAt() time.Time

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) GetID

func (d *Base) GetID() primitive.ObjectID

GetID returns a document's ID

func (*Base) GetTimeStamps

func (d *Base) GetTimeStamps() map[string]formattedTimestamp

func (*Base) GetUpdatedAt

func (d *Base) GetUpdatedAt() time.Time

GetUpdatedAt returns a document's last update time

func (*Base) IsNew

func (d *Base) IsNew() bool

IsNew returns a document's initialization state.

func (*Base) SetIsNew

func (d *Base) SetIsNew(status bool)

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.

func (*Base) Setup

func (d *Base) Setup() error

Setup initializes a document with ID and Timestamps

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL