document

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package document holds typed column descriptors and relation descriptors for the Document model.

Index

Constants

This section is empty.

Variables

View Source
var (
	ID        = base.ID
	TenantID  = base.TenantID
	Title     = base.Title
	Body      = base.Body
	Embedding = base.Embedding
	Status    = base.Status
	CreatedAt = base.CreatedAt
)
View Source
var Comments = momo.Relation[example.Document, example.Comment]{
	Name:        "Comments",
	Kind:        momo.HasMany,
	Parent:      momo.TableRef{Name: "documents"},
	Child:       momo.TableRef{Name: "comments"},
	ParentMeta:  (*example.Document)(nil).MomoMeta(),
	ChildMeta:   (*example.Comment)(nil).MomoMeta(),
	ParentCols:  []string{"id"},
	ChildCols:   []string{"document_id"},
	ChildPK:     []string{"id"},
	ParentKey:   func(p *example.Document) ([]any, bool) { return []any{p.ID}, true },
	ChildKey:    func(c *example.Comment) ([]any, bool) { return []any{c.DocumentID}, true },
	SetChildKey: func(c *example.Comment, k []any) { c.DocumentID = k[0].(int64) },
	GetMany:     func(p *example.Document) []example.Comment { return p.Comments },
	SetMany:     func(p *example.Document, cs []example.Comment) { p.Comments = cs },
}

Comments is the has_many relation of Document.

View Source
var Table = momo.TableRef{Name: "documents"}

Table is the base table reference.

View Source
var Tags = momo.Relation[example.Document, example.Tag]{
	Name:       "Tags",
	Kind:       momo.ManyToMany,
	Parent:     momo.TableRef{Name: "documents"},
	Child:      momo.TableRef{Name: "tags"},
	ParentMeta: (*example.Document)(nil).MomoMeta(),
	ChildMeta:  (*example.Tag)(nil).MomoMeta(),
	ParentCols: []string{"id"},
	ChildCols:  []string{"id"},
	ChildPK:    []string{"id"},
	Through:    &momo.Through{Table: momo.TableRef{Name: "document_tags"}, ParentCols: []string{"document_id"}, ChildCols: []string{"tag_id"}},
	ParentKey:  func(p *example.Document) ([]any, bool) { return []any{p.ID}, true },
	ChildKey:   func(c *example.Tag) ([]any, bool) { return []any{c.ID}, true },
	GetMany:    func(p *example.Document) []example.Tag { return p.Tags },
	SetMany:    func(p *example.Document, cs []example.Tag) { p.Tags = cs },
}

Tags is the many2many relation of Document.

View Source
var Tenant = momo.Relation[example.Document, example.Tenant]{
	Name:         "Tenant",
	Kind:         momo.BelongsTo,
	Parent:       momo.TableRef{Name: "documents"},
	Child:        momo.TableRef{Name: "tenants"},
	ParentMeta:   (*example.Document)(nil).MomoMeta(),
	ChildMeta:    (*example.Tenant)(nil).MomoMeta(),
	ParentCols:   []string{"tenant_id"},
	ChildCols:    []string{"id"},
	ChildPK:      []string{"id"},
	ParentKey:    func(p *example.Document) ([]any, bool) { return []any{p.TenantID}, true },
	ChildKey:     func(c *example.Tenant) ([]any, bool) { return []any{c.ID}, true },
	SetParentKey: func(p *example.Document, k []any) { p.TenantID = k[0].(int64) },
	GetOne:       func(p *example.Document) *example.Tenant { return p.Tenant },
	SetOne:       func(p *example.Document, c *example.Tenant) { p.Tenant = c },
}

Tenant is the belongs_to relation of Document.

Functions

func ColumnByName

func ColumnByName(name string) (momo.ColumnRef, error)

ColumnByName returns the typed column for an allowlisted external name. Names are matched exactly against database column names; relation fields and sensitive fields are not in the allowlist.

func ColumnNames

func ColumnNames() []string

ColumnNames lists the allowlisted names in declaration order.

Types

type Columns

type Columns struct {
	ID        momo.Column[int64]
	TenantID  momo.Column[int64]
	Title     momo.Column[string]
	Body      momo.Column[string]
	Embedding momo.VectorColumn[vector.Vector]
	Status    momo.Column[string]
	CreatedAt momo.ReadOnlyColumn[time.Time]
}

Columns is one alias's set of column descriptors.

func As

func As(alias string) Columns

As returns the column descriptors qualified by alias (the table name when alias is empty).

Jump to

Keyboard shortcuts

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