attribute

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 5 Imported by: 0

README

attribute

介绍

对MongoDB数据读写的封装,通过键值的结构存储数据

安装教程

go get github.com/jageros/hawox

使用例子
  1. 存储数据
package main

import (
	"github.com/jageros/hawox/attribute"
	"github.com/jageros/hawox/contextx"
	"github.com/jageros/hawox/logx"
)

func main() {
	ctx, cancel := contextx.Default()
	defer cancel()
	attribute.Initialize(ctx, func(opt *attribute.Option) {
		opt.Addr = "127.0.0.1:27017"
		opt.DBName = "attribute"
	})

	attr := attribute.NewAttrMgr("attr", "test")

	attrMap := attribute.NewMapAttr()
	attrMap.SetStr("name", "jackss")

	attr.SetMapAttr("info", attrMap)

	err := attr.Save(true)
	if err != nil {
		logx.Error(err)
	} else {
		logx.Info("save successful!")
	}

	err = ctx.Wait()
	logx.Infof("Stop With: %v", err)
}
  1. 读取数据
package main

import (
	"github.com/jageros/hawox/attribute"
	"github.com/jageros/hawox/contextx"
	"github.com/jageros/hawox/logx"
)

func main() {
	ctx, cancel := contextx.Default()
	defer cancel()
	attribute.Initialize(ctx, func(opt *attribute.Option) {
		opt.Addr = "127.0.0.1:27017"
		opt.DBName = "attribute"
	})

	attr := attribute.NewAttrMgr("attr", "test")
	err := attr.Load(true)
	if err != nil {
		logx.Error(err)
	} else {
		attrMap := attr.GetMapAttr("info")
		name := attrMap.GetStr("name")
		logx.Infof("Get Name=%s", name)
	}

	err = ctx.Wait()
	logx.Infof("Stop With: %v", err)
}
使用说明
  1. xxxx
  2. xxxx
  3. xxxx

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbConfigCreator db.IDbConfig
View Source
var NotExistsErr = errors.New("NotExistsErr")

Functions

func ForEach

func ForEach(attrName string, callback func(*AttrMgr))

func IDbConfigCreator

func IDbConfigCreator(opfs ...Opf) db.IDbConfig

func Initialize

func Initialize(ctx contextx.Context, opfs ...Opf)

Types

type AttrMgr

type AttrMgr struct {
	*MapAttr
	// contains filtered or unexported fields
}

func LoadAll

func LoadAll(attrName string) ([]*AttrMgr, error)

func NewAttrMgr

func NewAttrMgr(name string, id interface{}) *AttrMgr

func (*AttrMgr) Copy

func (a *AttrMgr) Copy(id interface{}, isSync ...interface{}) error

func (*AttrMgr) Delete

func (a *AttrMgr) Delete(needReply bool) error

func (AttrMgr) Dirty

func (a AttrMgr) Dirty() bool

func (*AttrMgr) Exists

func (a *AttrMgr) Exists() (bool, error)

func (*AttrMgr) GetAttrID

func (a *AttrMgr) GetAttrID() interface{}

func (*AttrMgr) Insert

func (a *AttrMgr) Insert() error

func (*AttrMgr) Load

func (a *AttrMgr) Load(isSync ...interface{}) error

func (*AttrMgr) Save

func (a *AttrMgr) Save(needReply bool) error

func (AttrMgr) SetDirty

func (a AttrMgr) SetDirty(val bool)

type ListAttr

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

func NewListAttr

func NewListAttr() *ListAttr

func (*ListAttr) Append

func (a *ListAttr) Append(val interface{})

func (*ListAttr) AppendBool

func (a *ListAttr) AppendBool(v bool)

func (*ListAttr) AppendFloat32

func (a *ListAttr) AppendFloat32(v float32)

func (*ListAttr) AppendInt

func (a *ListAttr) AppendInt(v int)

func (*ListAttr) AppendInt32

func (a *ListAttr) AppendInt32(v int32)

func (*ListAttr) AppendListAttr

func (a *ListAttr) AppendListAttr(attr *ListAttr)

func (*ListAttr) AppendMapAttr

func (a *ListAttr) AppendMapAttr(attr *MapAttr)

func (*ListAttr) AppendStr

func (a *ListAttr) AppendStr(v string)

func (*ListAttr) AppendUInt32

func (a *ListAttr) AppendUInt32(v uint32)

func (*ListAttr) AppendUInt64

func (a *ListAttr) AppendUInt64(v uint64)

func (*ListAttr) AssignList

func (a *ListAttr) AssignList(l []interface{})

func (*ListAttr) DelByIndex

func (a *ListAttr) DelByIndex(index int)

func (*ListAttr) DelBySection

func (a *ListAttr) DelBySection(beginIdx, endIdx int)

del [beginIdx, endIdx) beginIdx >= 0 endIdx <= list len

func (*ListAttr) DelInt

func (a *ListAttr) DelInt(val int) int

func (*ListAttr) DelMapAttr

func (a *ListAttr) DelMapAttr(val *MapAttr) int

func (*ListAttr) DelStr

func (a *ListAttr) DelStr(val string) int

func (*ListAttr) DelUint32

func (a *ListAttr) DelUint32(val uint32) int

func (*ListAttr) Dirty

func (a *ListAttr) Dirty() bool

func (*ListAttr) ForEachIndex

func (a *ListAttr) ForEachIndex(f func(index int) bool)

func (*ListAttr) ForIntervalIndex

func (a *ListAttr) ForIntervalIndex(startIndex, endIndex int, f func(index int) bool)

func (*ListAttr) ForOrderEachIndex

func (a *ListAttr) ForOrderEachIndex(order bool, num int, f func(index int) bool)

func (*ListAttr) Get

func (a *ListAttr) Get(index int) interface{}

func (*ListAttr) GetBool

func (a *ListAttr) GetBool(index int) bool

func (*ListAttr) GetFloat32

func (a *ListAttr) GetFloat32(index int) float32

func (*ListAttr) GetInt

func (a *ListAttr) GetInt(index int) int

func (*ListAttr) GetInt32

func (a *ListAttr) GetInt32(index int) int32

func (*ListAttr) GetListAttr

func (a *ListAttr) GetListAttr(index int) *ListAttr

func (*ListAttr) GetMapAttr

func (a *ListAttr) GetMapAttr(index int) *MapAttr

func (*ListAttr) GetStr

func (a *ListAttr) GetStr(index int) string

func (*ListAttr) GetUInt32

func (a *ListAttr) GetUInt32(index int) uint32

func (*ListAttr) GetUInt64

func (a *ListAttr) GetUInt64(index int) uint64

func (*ListAttr) PopBool

func (a *ListAttr) PopBool() bool

func (*ListAttr) PopFloat32

func (a *ListAttr) PopFloat32() float32

func (*ListAttr) PopInt

func (a *ListAttr) PopInt() int

func (*ListAttr) PopListAttr

func (a *ListAttr) PopListAttr() *ListAttr

func (*ListAttr) PopMapAttr

func (a *ListAttr) PopMapAttr() *MapAttr

func (*ListAttr) PopStr

func (a *ListAttr) PopStr() string

func (*ListAttr) SetBool

func (a *ListAttr) SetBool(index int, v bool)

func (*ListAttr) SetDirty

func (a *ListAttr) SetDirty(val bool)

func (*ListAttr) SetFloat32

func (a *ListAttr) SetFloat32(index int, v float32)

func (*ListAttr) SetInt

func (a *ListAttr) SetInt(index int, v int)

func (*ListAttr) SetInt32

func (a *ListAttr) SetInt32(index int, v int32)

func (*ListAttr) SetListAttr

func (a *ListAttr) SetListAttr(index int, attr *ListAttr)

func (*ListAttr) SetMapAttr

func (a *ListAttr) SetMapAttr(index int, attr *MapAttr)

func (*ListAttr) SetStr

func (a *ListAttr) SetStr(index int, v string)

func (*ListAttr) SetUInt32

func (a *ListAttr) SetUInt32(index int, v uint32)

func (*ListAttr) SetUInt64

func (a *ListAttr) SetUInt64(index int, v uint64)

func (*ListAttr) Size

func (a *ListAttr) Size() int

func (*ListAttr) String

func (a *ListAttr) String() string

func (*ListAttr) ToList

func (a *ListAttr) ToList() []interface{}

type MapAttr

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

func NewMapAttr

func NewMapAttr() *MapAttr

func (*MapAttr) AssignMap

func (a *MapAttr) AssignMap(doc map[string]interface{})

func (*MapAttr) AssignMapWithFilter

func (a *MapAttr) AssignMapWithFilter(doc map[string]interface{}, filter func(string) bool)

func (*MapAttr) Del

func (a *MapAttr) Del(key string)

func (*MapAttr) Dirty

func (a *MapAttr) Dirty() bool

func (*MapAttr) ForEachKey

func (a *MapAttr) ForEachKey(f func(key string) bool)

func (*MapAttr) Get

func (a *MapAttr) Get(key string) interface{}

func (*MapAttr) GetBool

func (a *MapAttr) GetBool(key string) bool

func (*MapAttr) GetFloat32

func (a *MapAttr) GetFloat32(key string) float32

func (*MapAttr) GetFloat64

func (a *MapAttr) GetFloat64(key string) float64

func (*MapAttr) GetInt

func (a *MapAttr) GetInt(key string) int

func (*MapAttr) GetInt32

func (a *MapAttr) GetInt32(key string) int32

func (*MapAttr) GetInt64

func (a *MapAttr) GetInt64(key string) int64

func (*MapAttr) GetListAttr

func (a *MapAttr) GetListAttr(key string) *ListAttr

func (*MapAttr) GetMapAttr

func (a *MapAttr) GetMapAttr(key string) *MapAttr

func (*MapAttr) GetStr

func (a *MapAttr) GetStr(key string) string

func (*MapAttr) GetUInt32

func (a *MapAttr) GetUInt32(key string) uint32

func (*MapAttr) GetUInt64

func (a *MapAttr) GetUInt64(key string) uint64

func (*MapAttr) HasKey

func (a *MapAttr) HasKey(key string) bool

func (*MapAttr) Keys

func (a *MapAttr) Keys() []string

func (*MapAttr) Set

func (a *MapAttr) Set(key string, val interface{})

func (*MapAttr) SetBool

func (a *MapAttr) SetBool(key string, v bool)

func (*MapAttr) SetDirty

func (a *MapAttr) SetDirty(val bool)

func (*MapAttr) SetFloat

func (a *MapAttr) SetFloat(key string, v float32)

func (*MapAttr) SetFloat64

func (a *MapAttr) SetFloat64(key string, v float64)

func (*MapAttr) SetInt

func (a *MapAttr) SetInt(key string, v int)

func (*MapAttr) SetInt32

func (a *MapAttr) SetInt32(key string, v int32)

func (*MapAttr) SetInt64

func (a *MapAttr) SetInt64(key string, v int64)

func (*MapAttr) SetListAttr

func (a *MapAttr) SetListAttr(key string, attr *ListAttr)

func (*MapAttr) SetMapAttr

func (a *MapAttr) SetMapAttr(key string, attr *MapAttr)

func (*MapAttr) SetStr

func (a *MapAttr) SetStr(key string, v string)

func (*MapAttr) SetUInt32

func (a *MapAttr) SetUInt32(key string, v uint32)

func (*MapAttr) SetUInt64

func (a *MapAttr) SetUInt64(key string, v uint64)

func (*MapAttr) Size

func (a *MapAttr) Size() int

func (*MapAttr) String

func (a *MapAttr) String() string

func (*MapAttr) ToMap

func (a *MapAttr) ToMap() map[string]interface{}

func (*MapAttr) ToMapWithFilter

func (a *MapAttr) ToMapWithFilter(filter func(string) bool) map[string]interface{}

type Opf

type Opf func(opt *Option)

func MongoDBConfig

func MongoDBConfig(addr, dbName string) Opf

type Option

type Option struct {
	Addr     string
	DBName   string
	User     string
	Password string
}

func DefaultOption

func DefaultOption() *Option

func (*Option) GetAddr

func (op *Option) GetAddr() string

func (*Option) GetDB

func (op *Option) GetDB() string

func (*Option) GetPassword

func (op *Option) GetPassword() string

func (*Option) GetUser

func (op *Option) GetUser() string

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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