database

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

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

Database is the main entry point for the neat package.

func New

func New(cfg db.DBConfig, opts ...Option) (*Database, error)

New creates a new Database instance from a DBConfig.

func NewFromDSN

func NewFromDSN(dsn string, opts ...Option) (*Database, error)

NewFromDSN creates a new Database instance from a DSN string. Supported DSN formats: - postgres://user:pass@localhost:5432/mydb?sslmode=disable - mysql://user:pass@localhost:3306/mydb - sqlite://path/to/database.db

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection.

func (*Database) Connection

func (d *Database) Connection(name string) (*Database, error)

Connection returns a new Database instance for a different connection.

func (*Database) DB

func (d *Database) DB() (*sql.DB, error)

DB returns the underlying database connection.

func (*Database) DatabaseName

func (d *Database) DatabaseName() string

DatabaseName returns the name of the current database.

func (*Database) DisableQueryLog

func (d *Database) DisableQueryLog()

DisableQueryLog disables the capturing of executed queries.

func (*Database) EnableQueryLog

func (d *Database) EnableQueryLog()

EnableQueryLog enables the capturing of executed queries.

func (*Database) Factory added in v0.3.0

func (d *Database) Factory() orm.Factory

Factory returns the ORM factory for creating test data.

func (*Database) FlushQueryLog

func (d *Database) FlushQueryLog()

FlushQueryLog clears the captured queries from the log.

func (*Database) GetQueryLog

func (d *Database) GetQueryLog() []orm.QueryLog

GetQueryLog retrieves the captured queries from the log.

func (*Database) Migrate added in v0.3.0

func (d *Database) Migrate(paths ...string) error

Migrate runs all pending migrations.

func (*Database) MigrateDown added in v0.3.0

func (d *Database) MigrateDown(step int, paths ...string) error

MigrateDown rolls back the last migration batch.

func (*Database) MigrateFresh added in v0.3.0

func (d *Database) MigrateFresh(paths ...string) error

MigrateFresh drops all tables and re-runs all migrations.

func (*Database) MigrateReset added in v0.3.0

func (d *Database) MigrateReset(paths ...string) error

MigrateReset rolls back all migrations and re-runs them.

func (*Database) MigrationStatus added in v0.3.0

func (d *Database) MigrationStatus(paths ...string) ([]contractsMigration.Status, error)

MigrationStatus returns the status of all migrations.

func (*Database) Name added in v0.2.0

func (d *Database) Name() string

Name returns the name of the current connection.

func (*Database) Observe added in v0.3.0

func (d *Database) Observe(model any, observer orm.Observer)

Observe registers an observer for the given model.

func (*Database) Query

func (d *Database) Query() orm.Query

Query returns the ORM query builder.

func (*Database) Schema

func (d *Database) Schema() *schema.Schema

Schema returns the schema builder.

func (*Database) Seed added in v0.3.0

func (d *Database) Seed(seeders []contractsseeder.Seeder) error

Seed runs the specified seeders.

func (*Database) SeedOnce added in v0.3.0

func (d *Database) SeedOnce(seeders []contractsseeder.Seeder) error

SeedOnce runs the specified seeders only once.

func (*Database) Seeder added in v0.3.0

func (d *Database) Seeder() contractsseeder.Facade

Seeder returns a seeder facade for advanced seeder operations.

func (*Database) Transaction

func (d *Database) Transaction(txFunc func(tx orm.Query) error, opts ...*sql.TxOptions) error

Transaction executes a function within a database transaction.

type Option

type Option func(*options)

Option is a functional option for configuring the Database.

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the context for the database.

func WithEventBus

func WithEventBus(eventBus *databaseorm.EventBus) Option

WithEventBus sets the event bus for the database.

func WithLogger

func WithLogger(logger log.Log) Option

WithLogger sets the logger for the database.

func WithPool

func WithPool(pool db.PoolConfig) Option

WithPool sets the connection pool configuration for the database.

Jump to

Keyboard shortcuts

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