Documentation ¶
Index ¶
- type BaseModel
- type Cache
- type Collection
- type DBName
- type Database
- type Helix
- type Model
- type MongoDB
- type MongoRepository
- func (r *MongoRepository) DeleteOne(ctx context.Context, filter bson.M, opts ...*options.DeleteOptions) error
- func (r *MongoRepository) FindAll(ctx context.Context, filter bson.M, list interface{}, ...) error
- func (r *MongoRepository) FindOne(ctx context.Context, filter bson.M, document Model, ...) error
- func (r *MongoRepository) InsertOne(ctx context.Context, document Model, opts ...*options.InsertOneOptions) error
- func (r *MongoRepository) ReplaceOne(ctx context.Context, filter bson.M, replacement Model, ...) error
- type Redis
- type Repository
- type TwitchAPI
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct { ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` CreatedAt time.Time `bson:"createdAt" json:"createdAt"` UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // contains filtered or unexported fields }
BaseModel includes fields shared by all models.
func NewBaseModel ¶
func NewBaseModel(r Repository) BaseModel
NewBaseModel provides a new base model with given repository.
func (*BaseModel) Created ¶
func (bm *BaseModel) Created()
Created populates createdat and updatedat fields.
func (*BaseModel) Loaded ¶
Loaded returns a flag indicating if the model was successfully loaded from db.
func (*BaseModel) SetID ¶
func (bm *BaseModel) SetID(id interface{})
SetId sets the object id field of the model.
func (*BaseModel) SetR ¶
func (bm *BaseModel) SetR(r Repository)
SetR sets a model's repository. Only use this in model list.
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error Get(ctx context.Context, key string, document interface{}) error }
Cache interface.
type Collection ¶
type Collection string
const ( CollectionUser Collection = "user" CollectionChannel Collection = "channel" CollectionCommand Collection = "command" )
type Database ¶
type Database interface { Disconnect(ctx context.Context) error Repository(db DBName, col Collection) Repository }
Database interface.
type Helix ¶
type Helix struct {
// contains filtered or unexported fields
}
type Model ¶
type Model interface { Created() Updated() SetID(id interface{}) SetLoaded(loaded bool) }
Model interface.
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MonogDB implements database interface.
func NewMongoDB ¶
NewMongoDB initializes and returns a new MongoDB instace.
func (*MongoDB) Disconnect ¶
Disconnect disconnects db.
func (*MongoDB) Repository ¶
func (db *MongoDB) Repository(dbName DBName, col Collection) Repository
Repository returns a new repository.
type MongoRepository ¶
type MongoRepository struct {
// contains filtered or unexported fields
}
MongoRepository implements the repository interface.
func NewRepository ¶
func NewRepository(c *mongo.Collection) *MongoRepository
NewRepository returns a new mongo repository.
func (*MongoRepository) DeleteOne ¶
func (r *MongoRepository) DeleteOne(ctx context.Context, filter bson.M, opts ...*options.DeleteOptions) error
DeleteOne deletes one document on db.
func (*MongoRepository) FindAll ¶
func (r *MongoRepository) FindAll(ctx context.Context, filter bson.M, list interface{}, opts ...*options.FindOptions) error
FindAll finds all documents
func (*MongoRepository) FindOne ¶
func (r *MongoRepository) FindOne(ctx context.Context, filter bson.M, document Model, opts ...*options.FindOneOptions) error
FindOne finds one document from db.
func (*MongoRepository) InsertOne ¶
func (r *MongoRepository) InsertOne(ctx context.Context, document Model, opts ...*options.InsertOneOptions) error
InsertOne inserts one model to db.
func (*MongoRepository) ReplaceOne ¶
func (r *MongoRepository) ReplaceOne(ctx context.Context, filter bson.M, replacement Model, opts ...*options.ReplaceOptions) error
ReplaceOne replaced one document in db.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis implements cache interface.
type Repository ¶
type Repository interface { InsertOne(ctx context.Context, document Model, opts ...*options.InsertOneOptions) error FindOne(ctx context.Context, filter bson.M, document Model, opts ...*options.FindOneOptions) error ReplaceOne(ctx context.Context, filter bson.M, replacement Model, opts ...*options.ReplaceOptions) error FindAll(ctx context.Context, filter bson.M, list interface{}, opts ...*options.FindOptions) error DeleteOne(ctx context.Context, filter bson.M, opts ...*options.DeleteOptions) error }
Repository interface.