datastore

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Container = &DataStoreContainer{}
)

Initialize a data storage container singleton instance

Functions

func InitializeDataStore

func InitializeDataStore(config *settings.Config) error

InitializeDataStore initializes data storage according to the config

func NewXOrmLoggerAdapter

func NewXOrmLoggerAdapter(showSql bool, logLevel settings.Level) xorm.Logger

NewXOrmLoggerAdapter returns a new XOrmLoggerAdapter instance

Types

type DataStore

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

DataStore represents a data storage containing a series of database shards

func NewDataStore

func NewDataStore(databases ...*Database) (*DataStore, error)

NewDataStore returns a new data storage by a series of database

func (*DataStore) Choose

func (s *DataStore) Choose(key int64) *Database

Choose returns a database instance by sharding key

func (*DataStore) DoTransaction

func (s *DataStore) DoTransaction(key int64, c *core.Context, fn func(sess *xorm.Session) error) (err error)

DoTransaction runs a new database transaction in a specific database by sharding key

func (*DataStore) Query

func (s *DataStore) Query(c *core.Context, key int64) *xorm.Session

Query returns a new database session in a specific database by sharding key

func (*DataStore) SyncStructs

func (s *DataStore) SyncStructs(beans ...any) error

SyncStructs updates database structs by database models

type DataStoreContainer

type DataStoreContainer struct {
	UserStore     *DataStore
	TokenStore    *DataStore
	UserDataStore *DataStore
}

DataStoreContainer contains all data storages

type Database

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

Database represents a database instance

func (*Database) DoTransaction

func (db *Database) DoTransaction(c *core.Context, fn func(sess *xorm.Session) error) (err error)

DoTransaction runs a new database transaction

func (*Database) NewSession

func (db *Database) NewSession(c *core.Context) *xorm.Session

NewSession starts a new session with the specified context

type XOrmContextAdapter

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

XOrmContextAdapter represents the context adapter for xorm

func NewXOrmContextAdapter

func NewXOrmContextAdapter(c *core.Context) *XOrmContextAdapter

func (*XOrmContextAdapter) Deadline

func (c *XOrmContextAdapter) Deadline() (deadline time.Time, ok bool)

Deadline does nothing

func (*XOrmContextAdapter) Done

func (c *XOrmContextAdapter) Done() <-chan struct{}

Done always returns nil

func (*XOrmContextAdapter) Err

func (c *XOrmContextAdapter) Err() error

Err always returns nil

func (*XOrmContextAdapter) Value

func (c *XOrmContextAdapter) Value(key any) any

Value returns the value associated with this context for key, or nil if no value is associated with key.

type XOrmLoggerAdapter

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

XOrmLoggerAdapter represents the logger adapter for xorm

func (XOrmLoggerAdapter) Debug

func (logger XOrmLoggerAdapter) Debug(v ...any)

Debug logs debug log

func (XOrmLoggerAdapter) Debugf

func (logger XOrmLoggerAdapter) Debugf(format string, v ...any)

Debugf logs debug log with custom format

func (XOrmLoggerAdapter) Error

func (logger XOrmLoggerAdapter) Error(v ...any)

Error logs error log

func (XOrmLoggerAdapter) Errorf

func (logger XOrmLoggerAdapter) Errorf(format string, v ...any)

Errorf logs error log with custom format

func (XOrmLoggerAdapter) Info

func (logger XOrmLoggerAdapter) Info(v ...any)

Info logs info log

func (XOrmLoggerAdapter) Infof

func (logger XOrmLoggerAdapter) Infof(format string, v ...any)

Infof logs info log with custom format

func (XOrmLoggerAdapter) IsShowSQL

func (logger XOrmLoggerAdapter) IsShowSQL() bool

IsShowSQL returns whether write sql to log

func (XOrmLoggerAdapter) Level

func (logger XOrmLoggerAdapter) Level() xorm.LogLevel

Level returns the logger level

func (XOrmLoggerAdapter) SetLevel

func (logger XOrmLoggerAdapter) SetLevel(l xorm.LogLevel)

SetLevel sets the logger level

func (XOrmLoggerAdapter) ShowSQL

func (logger XOrmLoggerAdapter) ShowSQL(show ...bool)

ShowSQL sets whether write sql to log

func (XOrmLoggerAdapter) Warn

func (logger XOrmLoggerAdapter) Warn(v ...any)

Warn logs warn log

func (XOrmLoggerAdapter) Warnf

func (logger XOrmLoggerAdapter) Warnf(format string, v ...any)

Warnf logs warn log with custom format

Jump to

Keyboard shortcuts

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