datacenter

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

README

边缘数据中心

简介

这里主要用来管理开发者数据,开发者可以使用RPC为RULEX数据中心提供接口,将自己的功能进行集成。对RULEX来说,相当于是借助开发者扩展了自己的功能。

原理

开发者定义表结构,RULEX获取到会后渲染出表格供给外部应用查询。

类型

  • LOCAL:本地设备
  • EXTERNAL:外部扩展设备

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB() *gorm.DB

* * 返回数据库查询句柄 *

func InitDataCenter

func InitDataCenter(rulex typex.RuleX)

func Name

func Name() string

* * 返回名称 *

func Query

func Query(goodsId, query string) ([]map[string]any, error)

func RegisterModel

func RegisterModel(dist ...interface{})

* * 注册数据模型 *

func Stop

func Stop()

* * 停止 *

Types

type Column

type Column struct {
	Name        string      `json:"name,omitempty"`
	Type        string      `json:"type,omitempty"`
	Value       interface{} `json:"value,omitempty"`
	Description string      `json:"description,omitempty"`
}

* * 列定义 *

type DataCenter

type DataCenter struct {
	ExternalDb DataSource
	LocalDb    DataSource
	// contains filtered or unexported fields
}

* * 留着未来扩充数据中心的功能 *

type DataSource

type DataSource interface {
	Init() error
	GetSchemaDetail(goodsId string) SchemaDetail // 表详情
	Query(goodsId, query string) ([]map[string]any, error)
}

* * 数据源接口 *

func InitExternalDb

func InitExternalDb(rulex typex.RuleX) DataSource

func InitLocalDb

func InitLocalDb(rulex typex.RuleX) DataSource

type ExternalDb

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

* * 外部扩展数据库 *

func (*ExternalDb) GetSchemaDetail

func (db *ExternalDb) GetSchemaDetail(goodsId string) SchemaDetail

func (*ExternalDb) Init

func (db *ExternalDb) Init() error

func (*ExternalDb) Name

func (db *ExternalDb) Name() string

func (*ExternalDb) Query

func (db *ExternalDb) Query(goodsId, query string) ([]map[string]any, error)

* * 去调用RPC的Query *

type LocalDb

type LocalDb struct {
	Sqlite *SqliteDAO
	// contains filtered or unexported fields
}

* * 本地数据库是Sqlite,用来存储比如Modbus等数据 *

func (*LocalDb) GetSchemaDetail

func (ldb *LocalDb) GetSchemaDetail(goodsId string) SchemaDetail

func (*LocalDb) Init

func (ldb *LocalDb) Init() error

func (*LocalDb) Query

func (ldb *LocalDb) Query(goodsId, query string) ([]map[string]any, error)

type SchemaDefine

type SchemaDefine struct {
	UUID    string   `json:"uuid"`
	Columns []Column `json:"columns"`
}

* * 表结构定义 *

func GetSchemaDefine

func GetSchemaDefine(goodsId string) (SchemaDefine, error)

func SchemaDefineList

func SchemaDefineList() ([]SchemaDefine, error)

* * 仓库列表 *

type SchemaDetail

type SchemaDetail struct {
	UUID string `json:"uuid"`
	Name string `json:"name"`
	// SchemaType 数据库类型,如果是"INTERNAL"则表示原始RULEX;如果是 "EXTERNAL" 则表示扩展设备
	// 该字段是为了扩展数据中心, 将数据中心扩展为通用的一个中间层
	SchemaType   string       `json:"schemaType"`
	LocalPath    string       `json:"local_path"`
	NetAddr      string       `json:"net_addr"`
	CreateTs     uint64       `json:"create_ts"`
	Size         float32      `json:"size"`
	StorePath    string       `json:"store_path"`
	SchemaDefine SchemaDefine `json:"schema_define"`
	Description  string       `json:"description"`
}

* * 数据仓库的详情 *

func GetSchemaDetail

func GetSchemaDetail(goodsId string) SchemaDetail

* * 获取仓库详情, 现阶段写死的, 后期会在proto中实现 *

func SchemaList

func SchemaList() []SchemaDetail

* * 获取表格定义 *

type SqliteDAO

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

* * Sqlite 数据持久层 *

func InitSqliteDAO

func InitSqliteDAO(engine typex.RuleX) *SqliteDAO

* * 初始化DAO *

Jump to

Keyboard shortcuts

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