db

package
v0.0.0-...-284234c Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

README

DB - database interface

Provides a high level pluggable abstraction for databases.

This might be removed

Don't use this. Run away. RUN AWAY

Interface

Initial thoughts lie around a CRUD interface. The number of times one has to write CRUD on top of database libraries, having to think through schema and data modelling based on different databases is a pain. Going lower level than this doesn't pose any value.

Event sourcing can be tackled in a separate package.

type DB interface {
	Init(...Option) error
	Read(id string) (Record, error)
	Create(id string, v Record) error
	Update(id string, v Record) error
	Delete(id string) error
	Search(md Metadata, limit, offset int64) ([]Record, error)
	String() string
}

type Metadata map[string]interface{}

type Record interface {
	Id() string
	Metadata() Metadata
	Bytes() []byte
	Scan(v interface{}) error
}

## Supported Databases

  • Platform
  • Cassandra
  • MariaDB
  • Elasticsearch

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDatabase = "micro"
	DefaultTable    = "micro"
)

Functions

func NewContext

func NewContext(ctx context.Context, c DB) context.Context

Types

type DB

type DB interface {
	Init(...Option) error
	Options() Options
	Read(id string) (Record, error)
	Create(r Record) error
	Update(r Record) error
	Delete(id string) error
	Search(md Metadata, limit, offset int64) ([]Record, error)
	String() string
	// Potential expiremental in memory DB
	// needs to be started/stopped to be part of a ring
	// Also publishing to notify this is querying dbs
	Start() error
	Stop() error
}

func FromContext

func FromContext(ctx context.Context) (DB, bool)

func NewDB

func NewDB(opts ...Option) DB

type Metadata

type Metadata map[string]interface{}

type Option

type Option func(*Options)

func Client

func Client(c client.Client) Option

func Database

func Database(d string) Option

func Table

func Table(t string) Option

type Options

type Options struct {
	Database string
	Table    string

	Client client.Client

	// For alternative options
	Context context.Context
}

type Record

type Record interface {
	Id() string
	Created() int64
	Updated() int64
	Metadata() Metadata
	Bytes() []byte
	Scan(v interface{}) error
}

func NewRecord

func NewRecord(id string, md Metadata, data interface{}) Record

Directories

Path Synopsis
Package go_micro_platform_db is a generated protocol buffer package.
Package go_micro_platform_db is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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