Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidDB = errors.New("invalid database, maybe not initialized") ErrUnknowDBType = errors.New("unknow database type, only support mysql or sqlite") ErrNotPtrStruct = errors.New("model is not pointer to structure") ErrNotPtrSlice = errors.New("not pointer to slice") ErrNotPtrInt64 = errors.New("not pointer to int64") ErrNilCount = errors.New("count parameter cannot be nil") ErrNilDest = errors.New("dest parameter cannot be nil") ErrEmptyFieldName = errors.New("field name cannot be empty") ErrNilValue = errors.New("value cannot be nil") ErrNotAddressableModel = errors.New("model is not addressable") ErrNotAddressableSlice = errors.New("slice is not addressable") ErrNotSetSlice = errors.New("slice cannot set") ErrIDRequired = errors.New("id is required") )
View Source
var (
DB *gorm.DB
)
Functions ¶
func Database ¶
Database creates and returns a generic database manipulator implementing types.Database interface. Provides comprehensive CRUD capabilities with advanced features like caching, hooks, and query building. Automatically enables debug mode when log level is set to debug.
Type Parameters:
- M: Model type that implements types.Model interface
Parameters:
- ctx: Required database context for request tracing and metadata. In service layer operations, pass a valid DatabaseContext to track requests. For non-service layer operations, pass nil.
Returns a database manipulator with full CRUD and query capabilities.
Features:
- Generic type safety for model operations
- Automatic debug mode based on configuration
- Context-aware operations for tracing
- Default query limit protection
- Panic protection for uninitialized database
Example:
// Service layer usage with context
db := Database[*User](ctx.DatabaseContext())
// Non-service layer usage
db := Database[*User](nil)
users := db.WithQuery(&User{Name: "John"}).List()
func InstallGormTracingPlugin ¶
InstallGormTracingPlugin installs the GORM tracing plugin to the given database instance
Types ¶
type GormTracingPlugin ¶
type GormTracingPlugin struct{}
GormTracingPlugin is a GORM plugin that adds distributed tracing to database operations
func (*GormTracingPlugin) Initialize ¶
func (p *GormTracingPlugin) Initialize(db *gorm.DB) error
Initialize initializes the plugin
func (*GormTracingPlugin) Name ¶
func (p *GormTracingPlugin) Name() string
Name returns the plugin name
Click to show internal directories.
Click to hide internal directories.