store

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileSystem media.Handler

FileSystem Media handler

Functions

func Init

func Init()

func Migrate

func Migrate() error

func RegisterAdapter

func RegisterAdapter(a Adapter)

func RegisterMediaHandler

func RegisterMediaHandler(name string, mh media.Handler)

RegisterMediaHandler saves reference to a media handler (file upload-download handler).

func UseMediaHandler

func UseMediaHandler(name, config string) error

UseMediaHandler sets specified media handler as default.

Types

type Adapter

type Adapter interface {

	// Open and configure the adapter
	Open(config config.StoreType) error
	// Close the adapter
	Close() error
	// IsOpen checks if the adapter is ready for use
	IsOpen() bool
	// GetName returns the name of the adapter
	GetName() string
	// Stats returns the DB connection stats object.
	Stats() any
	// GetDB returns the underlying DB connection
	GetDB() *gorm.DB

	// UserCreate creates user record
	UserCreate(user *model.User) error
	// UserGet returns record for a given user ID
	UserGet(uid types.Uid) (*model.User, error)
	// UserGetAll returns user records for a given list of user IDs
	UserGetAll(ids ...types.Uid) ([]*model.User, error)
	// FirstUser returns the first user
	FirstUser() (*model.User, error)
	// UserDelete deletes user record
	UserDelete(uid types.Uid, hard bool) error
	// UserUpdate updates user record
	UserUpdate(uid types.Uid, update types.KV) error

	// FileStartUpload initializes a file upload.
	FileStartUpload(fd *types.FileDef) error
	// FileFinishUpload marks file upload as completed, successfully or otherwise.
	FileFinishUpload(fd *types.FileDef, success bool, size int64) (*types.FileDef, error)
	// FileGet fetches a record of a specific file
	FileGet(fid string) (*types.FileDef, error)
	// FileDeleteUnused deletes records where UseCount is zero. If olderThan is non-zero, deletes
	// unused records with UpdatedAt before olderThan.
	// Returns array of FileDef.Location of deleted filerecords so actual files can be deleted too.
	FileDeleteUnused(olderThan time.Time, limit int) ([]string, error)

	GetUsers() ([]*model.User, error)
	GetUserById(id int64) (*model.User, error)
	GetUserByFlag(flag string) (*model.User, error)
	CreatePlatformUser(item *model.PlatformUser) (int64, error)
	GetPlatformUsersByUserId(userId int64) ([]*model.PlatformUser, error)
	GetPlatformUserByFlag(flag string) (*model.PlatformUser, error)
	UpdatePlatformUser(item *model.PlatformUser) error
	GetPlatformChannelByFlag(flag string) (*model.PlatformChannel, error)
	GetPlatformChannelsByPlatformIds(platformIds []int64) ([]*model.PlatformChannel, error)
	GetPlatformChannelsByChannelId(channelId int64) (*model.PlatformChannel, error)
	CreatePlatformChannel(item *model.PlatformChannel) (int64, error)
	CreatePlatformChannelUser(item *model.PlatformChannelUser) (int64, error)
	GetPlatformChannelUsersByUserFlag(userFlag string) ([]*model.PlatformChannelUser, error)
	GetMessage(flag string) (*model.Message, error)
	GetMessageByPlatform(platformId int64, platformMsgId string) (*model.Message, error)
	GetMessagesBySession(session string) ([]*model.Message, error)
	CreateMessage(message model.Message) error

	GetBot(id int64) (*model.Bot, error)
	GetBotByName(name string) (*model.Bot, error)
	CreateBot(bot *model.Bot) (int64, error)
	UpdateBot(bot *model.Bot) error
	DeleteBot(name string) error
	GetBots() ([]*model.Bot, error)
	GetPlatform(id int64) (*model.Platform, error)
	GetPlatformByName(name string) (*model.Platform, error)
	GetPlatforms() ([]*model.Platform, error)
	CreatePlatform(platform *model.Platform) (int64, error)
	GetChannel(id int64) (*model.Channel, error)
	GetChannelByName(name string) (*model.Channel, error)
	CreateChannel(channel *model.Channel) (int64, error)
	UpdateChannel(channel *model.Channel) error
	DeleteChannel(name string) error
	GetChannels() ([]*model.Channel, error)

	DataSet(uid types.Uid, topic, key string, value types.KV) error
	DataGet(uid types.Uid, topic, key string) (types.KV, error)
	DataList(uid types.Uid, topic string, filter types.DataFilter) ([]*model.Data, error)
	DataDelete(uid types.Uid, topic, key string) error
	ConfigSet(uid types.Uid, topic, key string, value types.KV) error
	ConfigGet(uid types.Uid, topic, key string) (types.KV, error)
	ListConfigByPrefix(uid types.Uid, topic string, prefix string) ([]*model.Config, error)
	ConfigDelete(uid types.Uid, topic string, key string) error
	OAuthSet(oauth model.OAuth) error
	OAuthGet(uid types.Uid, topic, t string) (model.OAuth, error)
	OAuthGetAvailable(t string) ([]model.OAuth, error)
	FormSet(formId string, form model.Form) error
	FormGet(formId string) (model.Form, error)
	PageSet(pageId string, page model.Page) error
	PageGet(pageId string) (model.Page, error)
	BehaviorSet(behavior model.Behavior) error
	BehaviorGet(uid types.Uid, flag string) (model.Behavior, error)
	BehaviorList(uid types.Uid) ([]*model.Behavior, error)
	BehaviorIncrease(uid types.Uid, flag string, number int) error
	ParameterSet(flag string, params types.KV, expiredAt time.Time) error
	ParameterGet(flag string) (model.Parameter, error)
	ParameterDelete(flag string) error
	CreateInstruct(instruct *model.Instruct) (int64, error)
	ListInstruct(uid types.Uid, isExpire bool, limit int) ([]*model.Instruct, error)
	UpdateInstruct(instruct *model.Instruct) error
	ListWebhook(uid types.Uid) ([]*model.Webhook, error)
	CreateWebhook(webhook *model.Webhook) (int64, error)
	UpdateWebhook(webhook *model.Webhook) error
	DeleteWebhook(id int64) error
	IncreaseWebhookCount(id int64) error
	GetWebhookBySecret(secret string) (*model.Webhook, error)
	GetWebhookByUidAndFlag(uid types.Uid, flag string) (*model.Webhook, error)

	CreateCounter(counter *model.Counter) (int64, error)
	IncreaseCounter(id, amount int64) error
	DecreaseCounter(id, amount int64) error
	ListCounter(uid types.Uid, topic string) ([]*model.Counter, error)
	GetCounter(id int64) (model.Counter, error)
	GetCounterByFlag(uid types.Uid, topic string, flag string) (model.Counter, error)

	GetAgents() ([]*model.Agent, error)
	GetAgentByHostid(uid types.Uid, topic string, hostid string) (*model.Agent, error)
	CreateAgent(agent *model.Agent) (int64, error)
	UpdateAgentLastOnlineAt(uid types.Uid, topic string, hostid string, lastOnlineAt time.Time) error
	UpdateAgentOnlineDuration(uid types.Uid, topic string, hostid string, offlineTime time.Time) error
}
var Database Adapter

type PersistentStorageInterface

type PersistentStorageInterface interface {
	Open(jsonConfig config.StoreType) error
	Close() error
	IsOpen() bool
	GetAdapter() Adapter
	DbStats() func() any
}

PersistentStorageInterface defines methods used for interaction with persistent storage.

Store is the main object for interacting with persistent storage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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