bunx

package
v0.0.0-...-3400737 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(db *bun.DB) error

Close closes the database connection

func NewDB

func NewDB(dsn string) (*bun.DB, error)

NewDB creates a new Bun database instance for PostgreSQL or SQLite based on DSN

func NewUUIDv7

func NewUUIDv7() string

NewUUIDv7 generates a time-ordered UUIDv7 string for database primary keys.

UUIDv7 provides:

  • Time-ordered sortability for better database index performance
  • Compatibility with both PostgreSQL and SQLite (no gen_random_uuid() dependency)
  • Monotonic ordering within the same millisecond

This function panics if UUID generation fails, which only occurs on catastrophic system failures (e.g., entropy source exhaustion). This is acceptable because:

  • UUID generation failure means the system cannot operate safely
  • All database ID generation would fail anyway
  • Explicit error handling adds complexity without practical benefit

Use this for all model ID fields instead of uuid.NewString() (UUIDv4).

Types

type DatabaseType

type DatabaseType string

DatabaseType represents the type of database

const (
	DatabaseTypePostgreSQL DatabaseType = "postgres"
	DatabaseTypeSQLite     DatabaseType = "sqlite"
)

func DetectDatabaseType

func DetectDatabaseType(dsn string) DatabaseType

DetectDatabaseType determines the database type from a DSN string

Jump to

Keyboard shortcuts

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