Documentation ¶
Index ¶
- Constants
- Variables
- func AutoMigrate[T comparable](tableName string, dbName ...string) error
- func BeforeDataWS(...)
- func BeforeServersData(fn func(data any, conn *ws.Conn))
- func DisableCache()
- func FlushCache()
- func GetAllColumnsTypes(table string, dbName ...string) map[string]string
- func GetAllTables(dbName ...string) []string
- func GetConnection(dbName ...string) (*mongo.Database, bool)
- func InitShell() bool
- func New(dbName string, dbDSN ...string) error
- func NewFromConnection(dbName string, dbConn *mongo.Database) error
- func RunEvery(t time.Duration, function any)
- func ShutdownDatabases(databasesName ...string) error
- func WithBus(bus *ksbus.Server) *ksbus.Server
- type Builder
- func (b *Builder[T]) All() ([]T, error)
- func (b *Builder[T]) Context(ctx context.Context) *Builder[T]
- func (b *Builder[T]) Database(dbName string) *Builder[T]
- func (b *Builder[T]) Debug() *Builder[T]
- func (b *Builder[T]) Delete() (int, error)
- func (b *Builder[T]) Drop() (int, error)
- func (b *Builder[T]) Insert(model *T) (int, error)
- func (b *Builder[T]) Limit(limit int) *Builder[T]
- func (b *Builder[T]) One() (T, error)
- func (b *Builder[T]) OrderBy(fields ...string) *Builder[T]
- func (b *Builder[T]) Page(pageNumber int) *Builder[T]
- func (b *Builder[T]) Select(columns ...string) *Builder[T]
- func (b *Builder[T]) Set(fieldsCommaSeparated string, args ...any) (int, error)
- func (b *Builder[T]) Where(fieldsCommaSeparated string, args ...any) *Builder[T]
- type BuilderM
- func (b *BuilderM) All() ([]map[string]any, error)
- func (b *BuilderM) Context(ctx context.Context) *BuilderM
- func (b *BuilderM) Database(dbName string) *BuilderM
- func (b *BuilderM) Debug() *BuilderM
- func (b *BuilderM) Delete() (int, error)
- func (b *BuilderM) Drop() (int, error)
- func (b *BuilderM) Insert(fieldsCommaSeparated string, fields_values ...any) (int, error)
- func (b *BuilderM) Limit(limit int) *BuilderM
- func (b *BuilderM) One() (map[string]any, error)
- func (b *BuilderM) OrderBy(fields ...string) *BuilderM
- func (b *BuilderM) Page(pageNumber int) *BuilderM
- func (b *BuilderM) Select(columns ...string) *BuilderM
- func (b *BuilderM) Set(fieldsCommaSeparated string, args ...any) (int, error)
- func (b *BuilderM) Where(fieldsCommaSeparated string, args ...any) *BuilderM
- type DatabaseEntity
- type TableEntity
Constants ¶
const ( Red = "\033[1;31m%v\033[0m\n" Green = "\033[1;32m%v\033[0m\n" Yellow = "\033[1;33m%v\033[0m\n" Blue = "\033[1;34m%v\033[0m\n" Magenta = "\033[5;35m%v\033[0m\n" )
const (
CACHE_TOPIC = "internal-db-cache"
)
Variables ¶
var ( // Debug when true show extra useful logs for queries executed for migrations and queries statements Debug = false // FlushCacheEvery execute korm.FlushCache() every 30 min by default, you should not worry about it, but useful that you can change it FlushCacheEvery = 30 * time.Minute // DefaultDB keep tracking of the first database connected DefaultDB = "" )
Functions ¶
func AutoMigrate ¶
func AutoMigrate[T comparable](tableName string, dbName ...string) error
func BeforeDataWS ¶
BeforeDataWS handle connections and data received before upgrading websockets, useful to handle authentication
func BeforeServersData ¶
BeforeServersData handle connections and data received from another server
func DisableCache ¶
func DisableCache()
DisableCache disable the cache system, if you are having problem with it, you can korm.FlushCache on command too
func FlushCache ¶
func FlushCache()
FlushCache send msg to the cache system to Flush all the cache, safe to use in concurrent mode, and safe to use in general, it's done every 30 minutes(korm.FlushCacheEvery) and on update , create, delete , drop
func GetAllColumnsTypes ¶
GetAllColumnsTypes get columns and types from the database
func GetAllTables ¶
GetAllTables get all tables for the optional dbName given, otherwise, if not args, it will return tables of the first connected database
func GetConnection ¶
GetConnection common way to get a connection,returned as *mongo.Database with ok bool
func InitShell ¶
func InitShell() bool
InitShell init the shell and return true if used to stop main
func ShutdownDatabases ¶
ShutdownDatabases shutdown many database, and detect if sql and mongo
Types ¶
type Builder ¶
type Builder[T comparable] struct { // contains filtered or unexported fields }
func BuilderS ¶
func BuilderS[T comparable](tableName ...string) *Builder[T]
func Model ¶
func Model[T comparable](tableName ...string) *Builder[T]
type BuilderM ¶
type BuilderM struct {
// contains filtered or unexported fields
}
func BuilderMap ¶
type DatabaseEntity ¶
type DatabaseEntity struct { Name string MongoConn *mongo.Database Tables []TableEntity }
func GetMemoryDatabase ¶
func GetMemoryDatabase(dbName string) (*DatabaseEntity, error)
GetMemoryDatabase return the first connected database korm.DefaultDatabase if dbName "" or "default" else the matched db
func GetMemoryDatabases ¶
func GetMemoryDatabases() []DatabaseEntity
GetMemoryDatabases get all databases from memory
type TableEntity ¶
type TableEntity struct { Pk string Name string Columns []string Types map[string]string ModelTypes map[string]string Tags map[string][]string }
func GetMemoryTable ¶
func GetMemoryTable(tbName string, dbName ...string) (TableEntity, error)
GetMemoryTable get a table from memory for specified or first connected db
func GetMemoryTables ¶
func GetMemoryTables(dbName ...string) ([]TableEntity, error)
GetMemoryTable get all tables from memory for specified or first connected db