database

package
v0.0.0-...-f8036e4 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Unlicense Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID   uint64 `gorm:"primarykey"`
	Name string `gorm:"uniqueIndex:uq_category_name;not null"`

	// Parent
	OwnerID uint64 `gorm:"uniqueIndex:uq_category_name;not null"`
	Owner   *Owner `gorm:"foreignKey:OwnerID"`

	// Children
	Centroids []*Centroid `gorm:"foreignKey:CategoryID;constraint:onUpdate:CASCADE,onDelete:CASCADE"`
	Documents []*Document `gorm:"foreignKey:CategoryID;constraint:onUpdate:CASCADE,onDelete:CASCADE"`
}

type Centroid

type Centroid struct {
	ID          uint64    `gorm:"primarykey"`
	Vector      []byte    `gorm:"not null"`
	LastUpdated time.Time `gorm:"index:idx_centroid_updated;not null"`

	// Parent
	CategoryID uint64    `gorm:"index:idx_centroid_category;not null"`
	Category   *Category `gorm:"foreignKey:CategoryID"`

	// Children
	Embeddings []*Embedding `gorm:"foreignKey:CentroidID;constraint:onUpdate:CASCADE,onDelete:CASCADE"`
}

type Database

type Database struct {
	Provider config.DatabaseProvider

	*gorm.DB
	// contains filtered or unexported fields
}

func New

func New(appCtx context.Context, cfg config.Database) (db *Database, err error)

func (*Database) Close

func (d *Database) Close() error

type Document

type Document struct {
	ID          uint64        `gorm:"primarykey"`
	Name        string        `gorm:"not null"`
	ExternalID  string        `gorm:"not null"`
	LastUpdated time.Time     `gorm:"index:idx_document_updated;not null"`
	Document    DocumentField `gorm:"not null"`

	// Parent
	CategoryID uint64    `gorm:"not null"`
	Category   *Category `gorm:"foreignKey:CategoryID"`

	// Children
	Embeddings []*Embedding `gorm:"foreignKey:DocumentID;constraint:onUpdate:CASCADE,onDelete:CASCADE"`
}

type DocumentField

type DocumentField json.RawMessage

func (DocumentField) JSON

func (d DocumentField) JSON() (value any)

func (*DocumentField) Scan

func (d *DocumentField) Scan(value any) error

Scan scan value into DocumentField, implements sql.Scanner interface

func (DocumentField) Value

func (d DocumentField) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Embedding

type Embedding struct {
	ID     uint64 `gorm:"primarykey"`
	Vector []byte `gorm:"not null"`

	// Parent
	DocumentID uint64    `gorm:"index:idx_embedding_document;not null"`
	Document   *Document `gorm:"foreignKey:DocumentID"`
	CentroidID uint64    `gorm:"index:idx_embedding_centroid;not null"`
	Centroid   *Centroid `gorm:"foreignKey:CentroidID"`
}

type Owner

type Owner struct {
	ID   uint64 `gorm:"primarykey"`
	Name string `gorm:"uniqueIndex:uq_owner_name;not null"`

	// Children
	Categories []*Category `gorm:"foreignKey:OwnerID;constraint:onUpdate:CASCADE,onDelete:CASCADE"`
}

Jump to

Keyboard shortcuts

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