db

package
v0.0.0-...-af0c24f Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFragmentTables

func CreateFragmentTables(db *gorm.DB) error

CreateFragmentTables creates tables for the fragments if they do not exist.

func NewDatabase

func NewDatabase(url string) (*gorm.DB, error)

NewDatabase initializes a new database connection with GORM using PostgreSQL. It also ensures the vector extension is enabled, checks its version, auto-migrates schemas, and creates fragment tables.

Types

type Actor

type Actor struct {
	ID   id.ID  `gorm:"type:uuid;primaryKey"`
	Name string `gorm:"type:varchar(255);not null"`

	Assistant bool `gorm:"type:boolean;not null;default:false"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Actor represents an entity in the system with a unique ID and name.

type Fragment

type Fragment struct {
	ID        id.ID           `gorm:"type:uuid;primaryKey"`
	ActorID   id.ID           `gorm:"type:uuid;not null;index"`
	SessionID id.ID           `gorm:"type:uuid;not null;index"`
	Content   string          `gorm:"type:text;not null"`
	Metadata  Metadata        `gorm:"type:jsonb;not null;default:'{}'::jsonb"`
	Embedding pgvector.Vector `gorm:"type:vector(1536)"`

	Actor   *Actor   `gorm:"foreignKey:ActorID"`
	Session *Session `gorm:"foreignKey:SessionID"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Fragment represents a data fragment stored in one of the fragment tables.

type FragmentTable

type FragmentTable string

FragmentTable defines the different types of fragment tables in the database.

const (
	FragmentTableInteraction FragmentTable = "interaction"
	FragmentTablePersonality FragmentTable = "personality"
	FragmentTableInsight     FragmentTable = "insight"
	FragmentTableTwitter     FragmentTable = "twitter"
)

type Metadata

type Metadata map[string]interface{}

Metadata represents a JSON object stored in the database.

func (Metadata) GetBool

func (m Metadata) GetBool(key string) bool

GetBool retrieves a boolean value from Metadata, returning false if not found or not a bool.

func (Metadata) GetFloat

func (m Metadata) GetFloat(key string) float64

GetFloat retrieves a float64 value from Metadata, returning 0 if not found or not a float64.

func (Metadata) GetString

func (m Metadata) GetString(key string) string

GetString retrieves a string value from Metadata, returning an empty string if not found or not a string.

func (*Metadata) Scan

func (m *Metadata) Scan(value interface{}) error

Scan implements the sql.Scanner interface for Metadata.

func (Metadata) Value

func (m Metadata) Value() (driver.Value, error)

Value implements the driver.Valuer interface for Metadata.

type Session

type Session struct {
	ID id.ID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Session represents a session with a unique ID.

Jump to

Keyboard shortcuts

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