storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InMemoryStr = "memory"
	DynamoDBStr = "dynamo"
	MongoDBStr  = "mongo"
)

Variables

This section is empty.

Functions

func GetStorageTypeStr

func GetStorageTypeStr(typ Type) string

Types

type Config

type Config struct {
	StorageType string        `json:",default=memory,options=memory|dynamo|mongo"`
	Region      string        `json:",optional"`
	Endpoint    string        `json:",optional"`
	Database    string        `json:",optional"`
	MaxLength   int           `json:",default=0"`
	Tick        time.Duration `json:",default=1s"`
	User        string        `json:",optional"`
	Password    string        `json:",optional"`
}

type Model

type Model core.Model

Model 存储基本模型

type Storage

type Storage interface {
	// CreateTable 创建一个新的存储对象表
	// 业务正常代码不用调用这个方法,请在测试时(例如单元测试写一个测试函数来创建)
	CreateTable(value interface{}, tableName string) error

	// Create 创建一个新的存储对象(单主键时主键不相同,主键+排序键时有一个不相同)
	// value 为符合 tag 定义的 struct
	Create(value interface{}, tableName string) error

	// Delete 删除一个存储对象(单主键时不需要额外参数,主键+排序键时需要把排序键的值作为额外参数)
	// value 为符合 tag 定义的 struct
	Delete(value interface{}, tableName string, hash interface{}, args ...interface{}) error

	// Save 保存一个存储对象(请勿用这个方法创建对象,可能会造成同步性问题)
	// value 为符合 tag 定义的 struct ptr(注:一定要是 struct ptr)
	Save(value interface{}, tableName string) error

	// First 获取符合要求的存储对象(单主键时不需要额外参数,主键+排序键时需要把排序键的值作为额外参数)
	// value 为符合 tag 定义的 struct ptr
	First(value interface{}, tableName string, hash interface{}, args ...interface{}) error

	// Find 获取所有符合要求的对象,性能远低于 First,请慎重使用
	// value 为符合 tag 定义的 struct slice ptr (注:&[]struct)
	// limit 为限制数量, <= 0 即不限制数量
	// expr 为表达式(空代表不使用表达式)
	// 其他为补充表达式的具体值
	Find(value interface{}, tableName string, limit int64, expr string, args ...interface{}) error
}

Storage 存储

func NewStorage

func NewStorage(config *Config) Storage

type Type

type Type uint8

Type 存储类型

const (
	// InMemory 内存存储,在单个服务内线程安全,不保证集群内的数据安全,非生产环境的选择,以及少数测试场景
	InMemory Type = iota
	// DynamoDB 借助 NoSQL 数据库的数据存取,保证集群内的数据安全,保证1秒内的数据最终一致性(只有货币相关操作是强一致性)
	// 每个接口调用小于 10ms
	DynamoDB
	// MongoDB 文档数据库
	MongoDB
)

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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