db

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	Username string
	Password string
	Database string
	Options  map[string]interface{}
}

Config 数据库配置结构

type DBInterface

type DBInterface interface {
	Connect(ctx context.Context) error
	Disconnect(ctx context.Context) error
	Ping(ctx context.Context) error
	IsConnected() bool
	Reconnect(ctx context.Context) error
}

DBInterface 定义所有数据库操作的通用接口

type DataOperation

type DataOperation interface {
	Create(ctx context.Context, collection string, data interface{}) error
	Read(ctx context.Context, collection string, filter interface{}, result interface{}) error
	Update(ctx context.Context, collection string, filter interface{}, update interface{}) error
	Delete(ctx context.Context, collection string, filter interface{}) error
	List(ctx context.Context, collection string, filter interface{}, results interface{}) error
}

DataOperation 定义基础的数据操作接口

type Etcd

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

func NewEtcd

func NewEtcd(config *Config) *Etcd

func (*Etcd) Connect

func (e *Etcd) Connect(ctx context.Context) error

func (*Etcd) Delete

func (e *Etcd) Delete(ctx context.Context, key string) error

func (*Etcd) Disconnect

func (e *Etcd) Disconnect(ctx context.Context) error

func (*Etcd) Get

func (e *Etcd) Get(ctx context.Context, key string) (string, error)

func (*Etcd) IsConnected

func (e *Etcd) IsConnected() bool

func (*Etcd) Ping

func (e *Etcd) Ping(ctx context.Context) error

func (*Etcd) Put

func (e *Etcd) Put(ctx context.Context, key, value string) error

Etcd specific operations

func (*Etcd) Reconnect

func (e *Etcd) Reconnect(ctx context.Context) error

func (*Etcd) Watch

func (e *Etcd) Watch(ctx context.Context, key string) clientv3.WatchChan

type MongoDB

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

func NewMongoDB

func NewMongoDB(config *Config) *MongoDB

func (*MongoDB) Connect

func (m *MongoDB) Connect(ctx context.Context) error

func (*MongoDB) Create

func (m *MongoDB) Create(ctx context.Context, collection string, data interface{}) error

CRUD operations

func (*MongoDB) Delete

func (m *MongoDB) Delete(ctx context.Context, collection string, filter interface{}) error

func (*MongoDB) Disconnect

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

func (*MongoDB) IsConnected

func (m *MongoDB) IsConnected() bool

func (*MongoDB) List

func (m *MongoDB) List(ctx context.Context, collection string, filter interface{}, results interface{}) error

func (*MongoDB) Ping

func (m *MongoDB) Ping(ctx context.Context) error

func (*MongoDB) Read

func (m *MongoDB) Read(ctx context.Context, collection string, filter interface{}, result interface{}) error

func (*MongoDB) Reconnect

func (m *MongoDB) Reconnect(ctx context.Context) error

func (*MongoDB) Update

func (m *MongoDB) Update(ctx context.Context, collection string, filter interface{}, update interface{}) error

type PostgreSQL

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

func NewPostgreSQL

func NewPostgreSQL(config *Config) *PostgreSQL

func (*PostgreSQL) Connect

func (p *PostgreSQL) Connect(ctx context.Context) error

func (*PostgreSQL) Create

func (p *PostgreSQL) Create(ctx context.Context, table string, data interface{}) error

CRUD operations

func (*PostgreSQL) Delete

func (p *PostgreSQL) Delete(ctx context.Context, table string, filter interface{}) error

func (*PostgreSQL) Disconnect

func (p *PostgreSQL) Disconnect(ctx context.Context) error

func (*PostgreSQL) IsConnected

func (p *PostgreSQL) IsConnected() bool

func (*PostgreSQL) List

func (p *PostgreSQL) List(ctx context.Context, table string, filter interface{}, results interface{}) error

func (*PostgreSQL) Ping

func (p *PostgreSQL) Ping(ctx context.Context) error

func (*PostgreSQL) Read

func (p *PostgreSQL) Read(ctx context.Context, table string, filter interface{}, result interface{}) error

func (*PostgreSQL) Reconnect

func (p *PostgreSQL) Reconnect(ctx context.Context) error

func (*PostgreSQL) Update

func (p *PostgreSQL) Update(ctx context.Context, table string, filter interface{}, update interface{}) error

type Redis

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

func NewRedis

func NewRedis(config *Config) *Redis

func (*Redis) Connect

func (r *Redis) Connect(ctx context.Context) error

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, key string) error

func (*Redis) Disconnect

func (r *Redis) Disconnect(ctx context.Context) error

func (*Redis) Exists

func (r *Redis) Exists(ctx context.Context, key string) (bool, error)

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string) (string, error)

func (*Redis) IsConnected

func (r *Redis) IsConnected() bool

func (*Redis) Ping

func (r *Redis) Ping(ctx context.Context) error

func (*Redis) Reconnect

func (r *Redis) Reconnect(ctx context.Context) error

func (*Redis) Set

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

Redis specific operations

type SQLServer

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

func NewSQLServer

func NewSQLServer(config *Config) *SQLServer

func (*SQLServer) Connect

func (s *SQLServer) Connect(ctx context.Context) error

func (*SQLServer) Create

func (s *SQLServer) Create(ctx context.Context, table string, data map[string]interface{}) error

CRUD operations

func (*SQLServer) Delete

func (s *SQLServer) Delete(ctx context.Context, table string, filter map[string]interface{}) error

func (*SQLServer) Disconnect

func (s *SQLServer) Disconnect(ctx context.Context) error

func (*SQLServer) IsConnected

func (s *SQLServer) IsConnected() bool

func (*SQLServer) List

func (s *SQLServer) List(ctx context.Context, table string, filter map[string]interface{}, results interface{}) error

func (*SQLServer) Ping

func (s *SQLServer) Ping(ctx context.Context) error

func (*SQLServer) Read

func (s *SQLServer) Read(ctx context.Context, table string, filter map[string]interface{}, result interface{}) error

func (*SQLServer) Reconnect

func (s *SQLServer) Reconnect(ctx context.Context) error

func (*SQLServer) Update

func (s *SQLServer) Update(ctx context.Context, table string, filter map[string]interface{}, update map[string]interface{}) error

Jump to

Keyboard shortcuts

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