adapter

package
v0.0.0-...-5bc2b8c Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package adapter abstracts a data source. An `Adapter` is an abstraction of a Data Source. Example of adatpers would be ElasticSearch, Redis, MongoDB, and SQL. All adapters should implement the same interface (IAdapter). The data - in, or out should be generic. Adapters should have a `name`, `description`. It should be able to read and write data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	// Name of the adapter.
	Name string `json:"name" validate:"required"`

	// Description of the adapter.
	Description string `json:"description"`
}

Adapter definition.

func New

func New(name, description string) (*Adapter, error)

New creates a new `Adapter`.

func (*Adapter) GetDescription

func (a *Adapter) GetDescription() string

GetDescription returns the `Description` of the `Adapter`.

func (*Adapter) GetName

func (a *Adapter) GetName() string

GetName returns the `Nane` of the adapter.

type IAdapter

type IAdapter[C any] interface {
	// GetDescription returns the `Description` of the `Adapter`.
	GetDescription() string

	// GetName returns the `Nane` of the adapter.
	GetName() string

	IDAO[C]
}

IAdapter defines what an `Adapter` must do.

type IDAO

type IDAO[C any] interface {
	// Read from data source.
	Read(ctx context.Context, o ...option.Func) ([]C, error)

	// Upsert write to the data source.
	Upsert(ctx context.Context, v []C, o ...option.Func) ([]byte, error)
}

IDAO defines how to read and upsert data.

Jump to

Keyboard shortcuts

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