database

package
v0.0.0-...-a75fe09 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const FilteredDataTableName = "filtered_data"
View Source
const ScrapedDataTableName = "scraped_data"

Variables

This section is empty.

Functions

This section is empty.

Types

type Db

type Db struct {
	Driver
}

Db is a facade that holds an instance of Driver and forwards its functions, Driver is interchangeable and allows the changing of database types. Db currently does not support context.Context.

func NewDb

func NewDb(d Driver) (*Db, error)

NewDb creates a new Db instance and attempts to connect the Driver to its database and Return an error in case connecting fails.

type Driver

type Driver interface {
	GetOne(table string, params map[string]any) (*Entity, error)
	GetMany(table string, params map[string]any) (ResultIterator, error)
	InsertOne(e *Entity) error
	InsertMany(entities []*Entity) error
	UpdateOne(e *Entity) error
	UpdateMany(table string, filter map[string]any, update map[string]any) error
	DeleteOne(e *Entity) error
	DeleteMany(table string, filter map[string]any) error
	// contains filtered or unexported methods
}

Driver holds functions to communicate with a database in a streamlined fashion, and is meant to be interchangeable so databases types can be easily switched if required. Driver currently does not support context.Context.

type Entity

type Entity struct {
	Id        any
	Table     string
	Data      map[string]any
	CreatedAt *time.Time
	UpdatedAt *time.Time
}

Entity holds results from DB queries and is used to interact with Driver. All data should be stored in Data, however it maps Id, CreatedAt and UpdatedAt for ease of access.

func NewEntity

func NewEntity(table string, data map[string]any) *Entity

func (*Entity) Get

func (e *Entity) Get(key string) any

Get attempts to fetch data from Entity by key, and returns it if matched or nil otherwise.

func (*Entity) GetString

func (e *Entity) GetString(key string) *string

GetString attempts to fetch data from Entity by key and checks if it is a string or not. If so, the string is returned or nil otherwise.

type MongoDbDriver

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

MongoDbDriver communicates with an instance of MongoDB and offers queries through the Driver interface. MongoDbDriver is currently not concurrency proof and does not cache any results.

func NewMongoDbDriver

func NewMongoDbDriver() *MongoDbDriver

func (*MongoDbDriver) DeleteMany

func (mdd *MongoDbDriver) DeleteMany(table string, filter map[string]any) error

DeleteMany deletes multiple rows within MongoDB based on the provided table and filter.

func (*MongoDbDriver) DeleteOne

func (mdd *MongoDbDriver) DeleteOne(e *Entity) error

func (*MongoDbDriver) GetMany

func (mdd *MongoDbDriver) GetMany(table string, params map[string]any) (ResultIterator, error)

func (*MongoDbDriver) GetOne

func (mdd *MongoDbDriver) GetOne(table string, params map[string]any) (*Entity, error)

func (*MongoDbDriver) InsertMany

func (mdd *MongoDbDriver) InsertMany(entities []*Entity) error

func (*MongoDbDriver) InsertOne

func (mdd *MongoDbDriver) InsertOne(e *Entity) error

func (*MongoDbDriver) UpdateMany

func (mdd *MongoDbDriver) UpdateMany(table string, filter map[string]any, update map[string]any) error

UpdateMany updates multiple rows within MongoDB based on the provided filter and fields to be updated.

func (*MongoDbDriver) UpdateOne

func (mdd *MongoDbDriver) UpdateOne(e *Entity) error

type MongoDbResultIterator

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

func (*MongoDbResultIterator) Next

func (mdri *MongoDbResultIterator) Next() (*Entity, error)

type ResultIterator

type ResultIterator interface {
	Next() (*Entity, error)
}

Jump to

Keyboard shortcuts

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