Documentation
¶
Index ¶
- Constants
- func New(cfg DBConfig, opts ...database.Option) (*database.Database, error)
- func NewFromDSN(dsn string, opts ...database.Option) (*database.Database, error)
- func NewFromSQLDB(sqlDB *sql.DB, 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 ¶
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 ¶
func New ¶ added in v0.2.0
New creates a new Database instance from a DBConfig. It converts the neat.DBConfig to the internal database.db.DBConfig and initializes the database.
func NewFromDSN ¶ added in v0.2.0
NewFromDSN creates a new Database instance from a DSN string. It parses the DSN and initializes the database connection.
func NewFromSQLDB ¶ added in v0.9.0
NewFromSQLDB creates a new Database instance from an already-open *sql.DB. The driver is auto-detected via reflection. Use database.WithDriver to override when auto-detection is not reliable. Neat does not close sqlDB or modify its connection-pool settings.
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.
func (ConnectionConfig) String ¶ added in v0.7.0
func (c ConnectionConfig) String() string
String returns a string representation of ConnectionConfig with password masked.
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.
func (*DBConfig) Add ¶
Add implements config.Config interface for DBConfig (stub). It adds a new configuration entry.
func (*DBConfig) Env ¶
Env implements config.Config interface for DBConfig (stub). It retrieves an environment variable value.
func (*DBConfig) Get ¶
Get implements config.Config interface for DBConfig. It retrieves any value from the configuration based on the given path.
func (*DBConfig) GetBool ¶
GetBool implements config.Config interface for DBConfig. It retrieves a boolean value from the configuration based on the given path.
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 NewEventBus ¶ added in v0.2.0
func NewEventBus() *EventBus
NewEventBus creates a new EventBus. It initializes an empty event bus with no registered listeners.
func (*EventBus) Dispatch ¶ added in v0.2.0
Dispatch dispatches an event to all registered listeners. It calls each handler synchronously in the order they were registered.
func (*EventBus) Forget ¶ added in v0.2.0
Forget removes all listeners for the given event name. This clears all handlers registered for the specified event.
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. The handler will be called whenever the event is dispatched.
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
|
|
|
migrator-migrations
command
|
|
|
migrator-transaction-failure
command
|
|
|
migrator-transactions
command
|
|
|
models
command
|
|
|
observers
command
|
|
|
schema-builder
command
|
|
|
seeders
command
|
|
|
soft-delete-alt-deleted-at
command
|
|
|
soft-delete-max-date
command
|
|
|
soft-deletes
command
|
|
|
sugar-methods
command
|
|
|
integration_tests
|
|
|
support
|
|