Documentation ¶
Index ¶
- func Connect(ctx context.Context) *mongo.Client
- func Disconnect(ctx context.Context)
- func Setup(db, host, port, password string)
- type Eloquent
- func (e *Eloquent[T]) All(ctx context.Context, opts ...*options.FindOptions) (models []*T, err error)
- func (e *Eloquent[T]) Count(ctx context.Context, filter any) (count int, err error)
- func (e *Eloquent[T]) Delete(ctx context.Context, id string) (deleteCount int, err error)
- func (e *Eloquent[T]) DeleteMultiple(ctx context.Context, filter any) (deleteCount int, err error)
- func (e *Eloquent[T]) Find(ctx context.Context, id string) (model *T, err error)
- func (e *Eloquent[T]) FindMultiple(ctx context.Context, filter any, opts ...*options.FindOptions) (models []*T, err error)
- func (e *Eloquent[T]) GetCollection() *mongo.Collection
- func (e *Eloquent[T]) Insert(ctx context.Context, data *T) (insertedID string, err error)
- func (e *Eloquent[T]) InsertMultiple(ctx context.Context, data []*T) (InsertedIDs []string, err error)
- func (e *Eloquent[T]) Paginate(ctx context.Context, limit int, page int, filter any) (paginated *Pagination[T], err error)
- func (e *Eloquent[T]) Update(ctx context.Context, id string, data *T) (modifiedCount int, err error)
- func (e *Eloquent[T]) UpdateMultiple(ctx context.Context, filter any, data *T) (modifiedCount int, err error)
- type IEloquent
- type Pagination
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Eloquent ¶
func NewEloquent ¶
func (*Eloquent[T]) All ¶
func (e *Eloquent[T]) All(ctx context.Context, opts ...*options.FindOptions) (models []*T, err error)
*
- @title get all document from collection
- @return models []*T your model slice
- @return err error fail message from query
func (*Eloquent[T]) Count ¶
*
- @title counter document
- @param filter any you can use struct, bson,etc .., or nil
- @return count int filter document count
- @return err error fail message from query
func (*Eloquent[T]) Delete ¶
*
- @title delete a document
- @param id string _id of document
- @return deleteCount int delete document count
- @return err error fail message from query
func (*Eloquent[T]) DeleteMultiple ¶
*
- @title delete Multiple document
- @param filter any ex:bson.M{}, struct, bson.D{}
- @return deleteCount int delete document count
- @return err error fail message from query
func (*Eloquent[T]) Find ¶
*
- @title find a document by _id
- @param id string _id of document
- @return model struct your model struct
- @return err error fail message from query
func (*Eloquent[T]) FindMultiple ¶
func (e *Eloquent[T]) FindMultiple(ctx context.Context, filter any, opts ...*options.FindOptions) (models []*T, err error)
*
- @title find multiple document
- @param filter any
- @return models []*T your model slice
- @return err error fail message from query
func (*Eloquent[T]) GetCollection ¶
func (e *Eloquent[T]) GetCollection() *mongo.Collection
*
- @title get collection instance
func (*Eloquent[T]) Insert ¶
*
- @title insert a document
- @param data *T your model struct
- @return insertedID string _id of mongodb
- @return err error fail message from query
func (*Eloquent[T]) InsertMultiple ¶
func (e *Eloquent[T]) InsertMultiple(ctx context.Context, data []*T) (InsertedIDs []string, err error)
*
- @title insert multiple document
- @param data []*T{} your model slice
- @return InsertedIDs []string _id of mongodb
- @return err error fail message from query
func (*Eloquent[T]) Paginate ¶
func (e *Eloquent[T]) Paginate(ctx context.Context, limit int, page int, filter any) (paginated *Pagination[T], err error)
*
- @title create pagination for your model data
- @param limit int how many data display in each page. default=10
- @param page int choose page for pagination. default=1
- @param filter any you can use struct, bson,etc ... . but reject pass nil to filter
- @return pagination *pagination[T]
- @return err error fail message from query
func (*Eloquent[T]) Update ¶
func (e *Eloquent[T]) Update(ctx context.Context, id string, data *T) (modifiedCount int, err error)
*
- @title update a document
- @param id string _id of mongodb
- @return modifiedCount int modified document count
- @return err error fail message from query
func (*Eloquent[T]) UpdateMultiple ¶
func (e *Eloquent[T]) UpdateMultiple(ctx context.Context, filter any, data *T) (modifiedCount int, err error)
*
- @title update multiple document
- @param filter any ex:struct, bson
- @return modifiedCount int modified document count
- @return err error fail message from query
type IEloquent ¶
type IEloquent[T any] interface { GetCollection() *mongo.Collection All(ctx context.Context, opts ...*options.FindOptions) (models []*T, err error) Find(ctx context.Context, id string) (model *T, err error) FindMultiple(ctx context.Context, filter any, opts ...*options.FindOptions) (models []*T, err error) Insert(ctx context.Context, data *T) (insertedID string, err error) InsertMultiple(ctx context.Context, data []*T) (InsertedIDs []string, err error) Delete(ctx context.Context, id string) (deleteCount int, err error) DeleteMultiple(ctx context.Context, filter any) (deleteCount int, err error) Update(ctx context.Context, id string, data *T) (modifiedCount int, err error) UpdateMultiple(ctx context.Context, filter any, data *T) (modifiedCount int, err error) Count(ctx context.Context, filter any) (count int, err error) Paginate(ctx context.Context, limit int, page int, filter any) (paginated *Pagination[T], err error) }
Click to show internal directories.
Click to hide internal directories.