easydb

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 0 Imported by: 0

README

Easydb

A library on go to access easily some databases. The main rule of this library is to follow a unique interface for all databases that we implemented. So, you will only need to know one library (easydb) for accessing many databases.

Supported databases

Getting started

Download

go get github.com/ednailson/easydb-go

Database Interface

The main principle of the library is the database interface.

Every implemented database follows this interface after created.

There is a New(...params) function for every database, and all of them there is their own config struct param. This function will return a database interface, so after that it will be the same usage for every database.

Check how to use it below.

Usage

Creating a database

We will create a mongoDB instance right now but you can created an instance of any easydb implemented database.

config := mongo.Config {
            Host:     "mongodb.service.com.br",
            Port:     27017,
            Database: "easydb_test",
            Username: "root",
            Password: "dummyPass",
}
db, err := mongo.NewDatabase(config)
Creating a table/collection
table, err := db.Table("easydb-table-example")

Now you can write or read from this table

Writing on a table/collection
writer := table.Writer()
writer.Save(`{"data": "your data"}`)
Reading on a table/collection
reader := table.Reader()
reader.Read("document-id")

Developer

Junior

Documentation

Index

Constants

View Source
const ApplicationName = "easydb-go"
View Source
const Version = "0.2.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Database added in v0.2.0

type Database interface {
	Table(table string) (Table, error)
	Query(query string) (interface{}, error)
	Errors() Errors
}

type Errors added in v0.2.0

type Errors interface {
	IsConflict(err error) bool
	IsNotFound(err error) bool
}

type Filter

type Filter struct {
	Key      string
	Value    interface{}
	Operator string
}

type Filters added in v0.2.0

type Filters struct {
	Filters []Filter
}

func NewFilters added in v0.2.0

func NewFilters() *Filters

func (*Filters) AddFilter added in v0.2.0

func (f *Filters) AddFilter(key string, value interface{}, operator string) *Filters

func (*Filters) Done added in v0.2.0

func (f *Filters) Done() []Filter

type Reader added in v0.2.0

type Reader interface {
	Read(id string) (interface{}, error)
	ReadAll() ([]interface{}, error)
	Filter(filters []Filter) ([]interface{}, error)
	Errors() Errors
}

type Table added in v0.2.0

type Table interface {
	Writer() Writer
	Reader() Reader
}

type Writer added in v0.2.0

type Writer interface {
	Save(data interface{}) (interface{}, error)
	Update(id string, data interface{}) (interface{}, error)
	Delete(id string) error
	Errors() Errors
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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