kormongo

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	CACHE_TOPIC = "internal-db-cache"
)

Variables

View Source
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

func BeforeDataWS(fn func(data map[string]any, conn *ws.Conn, originalRequest *http.Request) bool)

BeforeDataWS handle connections and data received before upgrading websockets, useful to handle authentication

func BeforeServersData

func BeforeServersData(fn func(data any, conn *ws.Conn))

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

func GetAllColumnsTypes(table string, dbName ...string) map[string]string

GetAllColumnsTypes get columns and types from the database

func GetAllTables

func GetAllTables(dbName ...string) []string

GetAllTables get all tables for the optional dbName given, otherwise, if not args, it will return tables of the first connected database

func GetConnection

func GetConnection(dbName ...string) (*mongo.Database, bool)

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 New

func New(dbName string, dbDSN ...string) error

func NewFromConnection

func NewFromConnection(dbName string, dbConn *mongo.Database) error

func RunEvery

func RunEvery(t time.Duration, function any)

func ShutdownDatabases

func ShutdownDatabases(databasesName ...string) error

ShutdownDatabases shutdown many database, and detect if sql and mongo

func WithBus

func WithBus(bus *ksbus.Server) *ksbus.Server

WithBus take ksbus.NewServer() that can be Run, RunTLS, RunAutoTLS

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]

func (*Builder[T]) All

func (b *Builder[T]) All() ([]T, error)

func (*Builder[T]) Context

func (b *Builder[T]) Context(ctx context.Context) *Builder[T]

func (*Builder[T]) Database

func (b *Builder[T]) Database(dbName string) *Builder[T]

func (*Builder[T]) Debug

func (b *Builder[T]) Debug() *Builder[T]

func (*Builder[T]) Delete

func (b *Builder[T]) Delete() (int, error)

func (*Builder[T]) Drop

func (b *Builder[T]) Drop() (int, error)

func (*Builder[T]) Insert

func (b *Builder[T]) Insert(model *T) (int, error)

func (*Builder[T]) Limit

func (b *Builder[T]) Limit(limit int) *Builder[T]

func (*Builder[T]) One

func (b *Builder[T]) One() (T, error)

func (*Builder[T]) OrderBy

func (b *Builder[T]) OrderBy(fields ...string) *Builder[T]

func (*Builder[T]) Page

func (b *Builder[T]) Page(pageNumber int) *Builder[T]

func (*Builder[T]) Select

func (b *Builder[T]) Select(columns ...string) *Builder[T]

Select usage: Select("email","password")

func (*Builder[T]) Set

func (b *Builder[T]) Set(fieldsCommaSeparated string, args ...any) (int, error)

Set usage: Set("email, is_admin","example@mail.com",true)

func (*Builder[T]) Where

func (b *Builder[T]) Where(fieldsCommaSeparated string, args ...any) *Builder[T]

type BuilderM

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

func BuilderMap

func BuilderMap(tableName string) *BuilderM

func Table

func Table(tableName string) *BuilderM

func (*BuilderM) All

func (b *BuilderM) All() ([]map[string]any, error)

func (*BuilderM) Context

func (b *BuilderM) Context(ctx context.Context) *BuilderM

func (*BuilderM) Database

func (b *BuilderM) Database(dbName string) *BuilderM

func (*BuilderM) Debug

func (b *BuilderM) Debug() *BuilderM

func (*BuilderM) Delete

func (b *BuilderM) Delete() (int, error)

func (*BuilderM) Drop

func (b *BuilderM) Drop() (int, error)

func (*BuilderM) Insert

func (b *BuilderM) Insert(fieldsCommaSeparated string, fields_values ...any) (int, error)

Insert usage: Insert("email, is_admin","example@mail.com",true)

func (*BuilderM) Limit

func (b *BuilderM) Limit(limit int) *BuilderM

func (*BuilderM) One

func (b *BuilderM) One() (map[string]any, error)

func (*BuilderM) OrderBy

func (b *BuilderM) OrderBy(fields ...string) *BuilderM

func (*BuilderM) Page

func (b *BuilderM) Page(pageNumber int) *BuilderM

func (*BuilderM) Select

func (b *BuilderM) Select(columns ...string) *BuilderM

func (*BuilderM) Set

func (b *BuilderM) Set(fieldsCommaSeparated string, args ...any) (int, error)

Set usage: Set("email, is_admin","example@mail.com",true)

func (*BuilderM) Where

func (b *BuilderM) Where(fieldsCommaSeparated string, args ...any) *BuilderM

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

Jump to

Keyboard shortcuts

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