db

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthorBooksRel = drel.RelationInfo{
	Name:        "Books",
	Type:        drel.HasMany,
	FKColumn:    "author_id",
	RelatedMeta: drel.ToMetaBase(&models.BookMeta),
	FieldSetter: func(parent any, related any) {
		p := parent.(*models.Author)
		items := related.([]any)
		result := make([]*models.Book, len(items))
		for i, item := range items {
			result[i] = item.(*models.Book)
		}
		p.Books = result
	},
}
View Source
var AuthorIncludeBooks = drel.NewIncludeSpec(&AuthorBooksRel)
View Source
var AuthorIncludeProfile = drel.NewIncludeSpec(&AuthorProfileRel)
View Source
var AuthorProfileRel = drel.RelationInfo{
	Name:        "Profile",
	Type:        drel.HasOne,
	FKColumn:    "author_id",
	RelatedMeta: drel.ToMetaBase(&models.AuthorProfileMeta),
	FieldSetter: func(parent any, related any) {
		p := parent.(*models.Author)
		p.Profile = related.(*models.AuthorProfile)
	},
}
View Source
var BookAuthorRel = drel.RelationInfo{
	Name:        "Author",
	Type:        drel.BelongsTo,
	FKColumn:    "author_id",
	RelatedMeta: drel.ToMetaBase(&models.AuthorMeta),
	FieldSetter: func(parent any, related any) {
		p := parent.(*models.Book)
		p.Author = related.(*models.Author)
	},
}
View Source
var BookIncludeAuthor = drel.NewIncludeSpec(&BookAuthorRel)

Functions

This section is empty.

Types

type DB

type DB struct {
	*drel.Engine
	Authors        *models.AuthorRepository
	AuthorProfiles *models.AuthorProfileRepository
	Books          *models.BookRepository
}

func Open

func Open(dsn string, opts ...drel.Option) (*DB, error)

func (*DB) NewUnitOfWork added in v0.3.0

func (db *DB) NewUnitOfWork() *UnitOfWork

NewUnitOfWork starts a new change-tracking work session.

type UnitOfWork added in v0.3.0

type UnitOfWork struct {
	*drel.UnitOfWork
	Authors        *models.UoWAuthorRepository
	AuthorProfiles *models.UoWAuthorProfileRepository
	Books          *models.UoWBookRepository
}

UnitOfWork is a change-tracking work session with typed, tracked repositories. Load through uow.<Model>, stage with Add/Remove, then SaveChanges to flush everything in a single transaction.

Jump to

Keyboard shortcuts

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