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 ( SortAsc = orm.SortAsc SortDesc = orm.SortDesc )
Sort directions accepted by orm.Query.OrderBy. These are aliases for orm.SortAsc and orm.SortDesc β the canonical source of truth lives in contracts/database/orm.
const ( NullDate = "0002-01-01" NullDateTime = "0002-01-01 00:00:00" MaxDate = "9999-12-31" MaxDateTime = "9999-12-31 23:59:59" )
Sentinel date/time values for use as column defaults, sentinel values, and soft-delete strategies.
NullDate / NullDateTime represent the earliest valid date in the Gregorian calendar (1 AD β there is no year 0). Use these as NOT NULL sentinels for "no value" instead of NULL.
MaxDate / MaxDateTime represent the latest representable date/time. Use these as NOT NULL sentinels for "not deleted" in max-date soft-delete strategies.
const ( Yes = "yes" No = "no" )
Common string constants for yes/no values.
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
|
|
|
array-driver
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
|
|