Documentation
¶
Index ¶
- func Setup(db, host, port, password string)
- type Eloquent
- func (e *Eloquent[T]) All(opts ...*options.FindOptions) (models []*T, err error)
- func (e *Eloquent[T]) Close(client *mongo.Client)
- func (e *Eloquent[T]) Connect() (client *mongo.Client)
- func (e *Eloquent[T]) Count(filter any) (count int, err error)
- func (e *Eloquent[T]) Delete(id string) (deleteCount int, err error)
- func (e *Eloquent[T]) DeleteMultiple(filter any) (deleteCount int, err error)
- func (e *Eloquent[T]) Find(id string) (model *T, err error)
- func (e *Eloquent[T]) FindMultiple(filter any, opts ...*options.FindOptions) (models []*T, err error)
- func (e *Eloquent[T]) GetCollection(client *mongo.Client) *mongo.Collection
- func (e *Eloquent[T]) Insert(data *T) (insertedID string, err error)
- func (e *Eloquent[T]) InsertMultiple(data []*T) (InsertedIDs []string, err error)
- func (e *Eloquent[T]) Paginate(limit int, page int, filter any) (paginated *Pagination[T], err error)
- func (e *Eloquent[T]) Update(id string, data *T) (modifiedCount int, err error)
- func (e *Eloquent[T]) UpdateMultiple(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(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(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(client *mongo.Client) *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 ¶
*
- @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(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
type IEloquent ¶
type IEloquent[T any] interface { Connect() (client *mongo.Client) Close(client *mongo.Client) GetCollection(client *mongo.Client) *mongo.Collection All(opts ...*options.FindOptions) (models []*T, err error) Find(id string) (model *T, err error) FindMultiple(filter any, opts ...*options.FindOptions) (models []*T, err error) Insert(data *T) (insertedID string, err error) InsertMultiple(data []*T) (InsertedIDs []string, err error) Delete(id string) (deleteCount int, err error) DeleteMultiple(filter any) (deleteCount int, err error) Update(id string, data *T) (modifiedCount int, err error) UpdateMultiple(filter any, data *T) (modifiedCount int, err error) Count(filter any) (count int, err error) Paginate(limit int, page int, filter any) (paginated *Pagination[T], err error) }
Click to show internal directories.
Click to hide internal directories.