dataful

package module
v0.0.0-...-70c62f1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

README

dataful

Full of data related stuff

Dataful repo contains all data models and data related things used across amazeful packages.

Documentation

Index

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

func (bm *BaseModel) GetId() primitive.ObjectID

GetId gets the object id field of the model.

func (*BaseModel) Loaded

func (bm *BaseModel) Loaded() bool

Loaded returns a flag indicating if the model was successfully loaded from db.

func (*BaseModel) R

func (bm *BaseModel) R() Repository

R returns model repository.

func (*BaseModel) SetID

func (bm *BaseModel) SetID(id interface{})

SetId sets the object id field of the model.

func (*BaseModel) SetLoaded

func (bm *BaseModel) SetLoaded(loaded bool)

SetLoaded sets a model's loaded flag.

func (*BaseModel) SetR

func (bm *BaseModel) SetR(r Repository)

SetR sets a model's repository. Only use this in model list.

func (*BaseModel) Updated

func (bm *BaseModel) Updated()

Updated populates updatedat fields.

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"
	CollectionFilters Collection = "filters"
	CollectionPurge   Collection = "purge"
	CollectionAlerts  Collection = "alerts"
)

type DBName

type DBName string
const (
	DBAmazeful DBName = "Amazeful"
	DBLogs     DBName = "Logs"
	DBTest     DBName = "Test"
)

type Database

type Database interface {
	Disconnect(ctx context.Context) error
	Repository(db DBName, col Collection) Repository
}

Database interface.

type Model

type Model interface {
	Created()
	Updated()
	SetID(id interface{})
	GetId() primitive.ObjectID
	SetLoaded(loaded bool)
	SetR(r Repository)
}

Model interface.

type ModelList

type ModelList interface {
	SetLoaded()
	GetList() interface{}
	Loaded() bool
}

ModelList defines an interface used for array of models. All model list classes must implement ModelList interface.

type MongoDB

type MongoDB struct {
	// contains filtered or unexported fields
}

MonogDB implements database interface.

func NewMongoDB

func NewMongoDB(ctx context.Context, uri string) (*MongoDB, error)

NewMongoDB initializes and returns a new MongoDB instace.

func (*MongoDB) Disconnect

func (db *MongoDB) Disconnect(ctx context.Context) error

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 ModelList, 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.

func NewRedis

func NewRedis(ctx context.Context, redisURI string, redisPassword string) (*Redis, error)

NewRedis initializes and returns a new redis client.

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string, document interface{}) error

Get gets data from cache and unmarshals the data to provided document.

func (*Redis) Set

func (r *Redis) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set marshals the given value and adds it to cache.

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 ModelList, opts ...*options.FindOptions) error
	DeleteOne(ctx context.Context, filter bson.M, opts ...*options.DeleteOptions) error
}

Repository interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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