relational

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 6 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*bun.DB
}

func (*DB) CreateExtensions

func (db *DB) CreateExtensions(extensions []string) error

CreateExtensions - Creates a database extension if it doesn't already exist. Extensions are a Postgres concept, so requesting any on another dialect is an error rather than a silent no-op.

func (*DB) CreateTables

func (db *DB) CreateTables(models []interface{}) error

CreateTables - Creates the database schema if it doesn't already exist

func (*DB) RegisterModels

func (db *DB) RegisterModels(models []interface{}) error

RegisterModels - Registers many-to-many relationship

func (*DB) ResetTables

func (db *DB) ResetTables(models []interface{}) error

ResetTables - Drops and recreates the database schema

func (*DB) RollbackLastMigration

func (db *DB) RollbackLastMigration(migrations *migrate.Migrations) error

RollbackLastMigration - Rollbacks the last migration

func (*DB) RunMigrations

func (db *DB) RunMigrations(migrations *migrate.Migrations) error

RunMigrations - Executes all pending migrations

type DBModel

type DBModel interface {
	// Validate checks the model for logical and business-rule correctness.
	Validate() error

	// Insert validates and inserts the model into the DB.
	Insert(ctx context.Context, db bun.IDB) error

	// Update validates and updates the model in the DB.
	Update(ctx context.Context, db bun.IDB) error

	// Delete removes the model from the DB.
	Delete(ctx context.Context, db bun.IDB) error
}

DBModel defines the minimal interface for a model that can be persisted.

type Option

type Option func(db *DB) error

func WithExtensions

func WithExtensions(extensions []string) Option

func WithRegistrableModels

func WithRegistrableModels(models []interface{}) Option

type PaginableModel

type PaginableModel interface {
	// GetCursor returns a stable, opaque value representing the record’s
	// position in the sorted result set.
	GetCursor() string

	// GetSortField returns the DB column used for ordering in pagination queries.
	GetSortField() string

	// GetSortValue returns the value of the sort field for this record.
	GetSortValue() interface{}

	// GetUniqueField returns the DB column that uniquely identifies this record.
	GetUniqueField() string

	// GetUniqueValue returns the value of the unique field for this record.
	GetUniqueValue() interface{}
}

PaginableModel defines the minimal interface for cursor-based pagination.

Directories

Path Synopsis
internal
jsonfmt
Package jsonfmt holds the JSON formatter the compose dialects use in place of bun v1.3.0's, which mis-escapes the text \u0000 (https://github.com/uptrace/bun/issues/1472).
Package jsonfmt holds the JSON formatter the compose dialects use in place of bun v1.3.0's, which mis-escapes the text \u0000 (https://github.com/uptrace/bun/issues/1472).

Jump to

Keyboard shortcuts

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