Documentation
¶
Index ¶
- Constants
- func New(cfg DBConfig, opts ...database.Option) (*database.Database, error)
- func NewFromDSN(dsn string, opts ...database.Option) (*database.Database, error)
- type ConnectionConfig
- type DBConfig
- func (c *DBConfig) Add(name string, configuration any)
- func (c *DBConfig) Env(envName string, defaultValue ...any) any
- func (c *DBConfig) Get(path string, defaultValue ...any) any
- func (c *DBConfig) GetBool(path string, defaultValue ...any) bool
- func (c *DBConfig) GetInt(path string, defaultValue ...any) int
- func (c *DBConfig) GetString(path string, defaultValue ...any) string
- type Database
- type EventBus
- type EventHandler
- type MigrationConfig
- type PoolConfig
- type ReplicaConfig
Constants ¶
View Source
const ( EventCreating = "model.creating" EventCreated = "model.created" EventUpdating = "model.updating" EventUpdated = "model.updated" EventSaving = "model.saving" EventSaved = "model.saved" EventDeleting = "model.deleting" EventDeleted = "model.deleted" EventRestoring = "model.restoring" EventRestored = "model.restored" )
Event names for model lifecycle events.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConnectionConfig ¶
type ConnectionConfig struct {
Driver string // "postgres", "mysql", "sqlite", "sqlserver", "turso"
Dsn string
Host string
Port int
Database string
Username string
Password string
Charset string
Schema string // postgres only
SSLMode string // postgres only
Loc string // mysql only
Timezone string // postgres only
Prefix string
Singular bool
NoLowerCase bool
NameReplacer any
Read []ReplicaConfig
Write []ReplicaConfig
}
ConnectionConfig holds configuration for a single database connection.
type DBConfig ¶
type DBConfig struct {
// Default connection name
Default string
// Connection configurations
Connections map[string]ConnectionConfig
// Migration configuration
Migrations MigrationConfig
// Pool configuration
Pool PoolConfig
// Debug mode
Debug bool
// Slow query threshold in milliseconds
SlowThreshold int
}
DBConfig holds the database configuration for the standalone module.
type EventBus ¶ added in v0.2.0
type EventBus struct {
// contains filtered or unexported fields
}
EventBus is a lightweight internal event bus for model lifecycle events.
func (*EventBus) Dispatch ¶ added in v0.2.0
Dispatch dispatches an event to all registered listeners.
func (*EventBus) Listen ¶ added in v0.2.0
func (e *EventBus) Listen(eventName string, handler EventHandler)
Listen registers a handler for the given event name.
type EventHandler ¶ added in v0.2.0
type EventHandler func(event any)
EventHandler is a function that handles an event.
type MigrationConfig ¶
type MigrationConfig struct {
Driver string // "sql" or "orm"
Table string // default: "migrations"
}
MigrationConfig holds migration configuration.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
advanced-queries
command
|
|
|
basic-orm
command
|
|
|
configuration
command
|
|
|
factory
command
|
|
|
json-queries
command
|
|
|
migrations
command
|
|
|
models
command
|
|
|
observers
command
|
|
|
schema-builder
command
|
|
|
seeders
command
|
|
|
integration_tests
|
|
|
support
|
|
Click to show internal directories.
Click to hide internal directories.