storage

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 17 Imported by: 1 module, 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

View Source
const (
	OpEq       = "$eq"
	OpNe       = "$ne"
	OpLt       = "$lt"
	OpLte      = "$lte"
	OpGt       = "$gt"
	OpGte      = "$gte"
	OpContains = "$contains"
)

Filter operators supported on item lists.

Variables

This section is empty.

Functions

func CountUsers

func CountUsers() (int64, error)

CountUsers returns the total number of (non-deleted) users.

func CreateComponent

func CreateComponent(cmp *models.Component) error

CreateComponent stores a new Component definition in the DB, including its attributes.

func CreateSingleItem

func CreateSingleItem(st *models.Singleton, itemData map[string]any) (*models.SingleItem, error)

CreateSingleItem creates a new SingleItem for a given Singleton. Returns an error if an item already exists for that Singleton (one-to-one).

func CreateUser

func CreateUser(user *models.User) error

func DeleteAgent

func DeleteAgent(agentID uint) error

DeleteAgent deletes an agent from the database by its ID.

func DeleteCollection

func DeleteCollection(collectionID uint) error

DeleteCollection deletes a collection and all associated data by its ID.

func DeleteComponent

func DeleteComponent(name string) error

DeleteComponent removes a component definition by name. GORM's cascading delete will handle the attributes.

func DeleteItem

func DeleteItem(id uint) error

func DeleteRole

func DeleteRole(id uint) error

DeleteRole deletes a role by ID.

func DeleteSingleItem

func DeleteSingleItem(SingletonName string) error

DeleteSingleItem removes the SingleItem for a given single type name (if it exists).

func DeleteSingleton

func DeleteSingleton(SingletonID uint) error

DeleteSingleton permanently deletes a single type by its ID (including attributes). Note: Strapi typically doesn't expose DELETE for single types, but you can implement it if needed.

func DeleteUser

func DeleteUser(id uint) error

DeleteUser removes a user from the database by ID.

func FetchNestedRelations

func FetchNestedRelations(collection models.Collection, data models.JSONMap, level uint) (models.JSONMap, error)

func FindAgentsByEventTrigger

func FindAgentsByEventTrigger(collectionName string, eventType string) ([]models.Agent, error)

FindAgentsByEventTrigger queries for agents subscribed to a specific collection event. TOFIX This version uses a query for JSONB that is compatible with PostgreSQL.

func GetAgentByID

func GetAgentByID(id uint) (*models.Agent, error)

GetAgentByID retrieves an agent by its ID.

func GetAgentByName

func GetAgentByName(name string) (*models.Agent, error)

GetAgentByName retrieves an agent by its name.

func GetAllAgents

func GetAllAgents(filters map[string]any, rangeValues []int) ([]models.Agent, int, error)

GetAllAgents retrieves agents with optional filtering and pagination.

func GetAllCollections

func GetAllCollections(filters map[string]any, sortValues []string, rangeValues []int) ([]models.Collection, int, error)

func GetAllComponents

func GetAllComponents() ([]models.Component, error)

GetAllComponents returns every component definition with its attributes, ordered by name.

func GetAllRoles

func GetAllRoles() ([]models.UserRole, error)

GetAllRoles retrieves all roles from the database.

func GetAllSingletons

func GetAllSingletons() ([]models.Singleton, error)

GetAllSingletons returns every singleton definition with its attributes, ordered by name.

func GetAllUsers

func GetAllUsers() ([]models.User, error)

GetAllUsers retrieves all users from the database.

func GetCollectionByID

func GetCollectionByID(id uint) (*models.Collection, error)

GetCollectionByID retrieves a collection by its ID.

func GetCollectionByName

func GetCollectionByName(name string) (*models.Collection, error)

GetCollectionByName retrieves a collection by its name.

func GetCollectionSchema

func GetCollectionSchema(id int) (map[string]any, error)

GetCollectionSchema retrieves the schema definition of a collection by name.

func GetComponentByName

func GetComponentByName(name string) (*models.Component, error)

GetComponentByName retrieves a component definition by its name.

func GetConversationHistory

func GetConversationHistory(agentID uint) ([]llm.Message, error)

GetConversationHistory retrieves the messages for an agent.

func GetItemByID

func GetItemByID(collectionID uint, itemID uint) (*models.Item, error)

GetItemByID fetches an item by its ID and collection ID.

func GetItems

func GetItems(collectionID uint, page, pageSize int) ([]models.Item, int, error)

GetItems lists items using page/pageSize pagination (page starts at 1).

func GetItemsByOffset

func GetItemsByOffset(collectionID uint, offset, limit int) ([]models.Item, int, error)

GetItemsByOffset lists items using offset/limit pagination (as GraphQL does).

func GetRoleByID

func GetRoleByID(id uint) (*models.UserRole, error)

GetRoleByID retrieves a role by its ID.

func GetRoleByName

func GetRoleByName(name string) (*models.UserRole, error)

GetRoleByName retrieves a role by its name.

func GetSingleItemByType

func GetSingleItemByType(SingletonName string) (*models.SingleItem, error)

GetSingleItemByType retrieves the SingleItem for a given single type name.

func GetSingletonByName

func GetSingletonByName(name string) (*models.Singleton, error)

GetSingletonByName retrieves a single type by its name (including associated attributes).

func GetUserByID

func GetUserByID(id uint) (*models.User, error)

GetUserByID retrieves a user by their ID.

func GetUserByUsername

func GetUserByUsername(username string) (*models.User, error)

GetUserByUsername retrieves a user by their username.

func InitAsynqClient

func InitAsynqClient(client *asynq.Client)

func IsReferencedByOtherCollections

func IsReferencedByOtherCollections(collectionName string, tx *gorm.DB) ([]models.Attribute, error)

func QueryItems

func QueryItems(ct models.Collection, q ItemQuery) ([]models.Item, int, error)

QueryItems lists the items of a collection with optional filters and sort. Every field is validated against the collection schema; attribute names and values are always bound as SQL parameters.

func SaveAgent

func SaveAgent(agent *models.Agent) error

SaveAgent persists an Agent to the database, handling both new and soft-deleted records.

func SaveCollection

func SaveCollection(ct *models.Collection) error

SaveCollection persists a Collection to the database, handling both new and soft-deleted records.

func SaveConversationHistory

func SaveConversationHistory(agentID uint, messages []llm.Message) error

SaveConversationHistory replaces the old history with the new one for an agent.

func SaveItem

func SaveItem(collection models.Collection, itemData models.JSONMap) (*models.Item, error)

SaveItem validates and creates a single item, then publishes an 'item:created' event once the transaction has committed.

func SaveItems

func SaveItems(collection models.Collection, batch []models.JSONMap) ([]*models.Item, error)

SaveItems validates and creates several items atomically: either all are stored or none. Nested relations created during validation are part of the same transaction, and the stored data is the processed (validated) data. Events are published only after a successful commit.

func SaveOrUpdateSingleton

func SaveOrUpdateSingleton(st *models.Singleton) error

SaveOrUpdateSingleton either creates a new single type or updates/restores a previously soft-deleted record with the same name.

This mimics the "single type" behavior in Strapi (one record per name).

func SaveRole

func SaveRole(role *models.UserRole) error

CreateRole creates a new role.

func UpdateAgent

func UpdateAgent(id uint, updated *models.Agent) error

UpdateAgent updates an existing Agent in the database by its ID.

func UpdateCollection

func UpdateCollection(id uint, updated *models.Collection) error

UpdateCollectionByID updates an existing Collection in the database by its ID.

func UpdateComponent

func UpdateComponent(name string, updated *models.Component) error

UpdateComponent updates an existing component definition by name.

func UpdateItem

func UpdateItem(itemID uint, data models.JSONMap) error

func UpdateRole

func UpdateRole(id uint, updates map[string]interface{}) error

UpdateRole updates an existing role by ID.

func UpdateSingleItem

func UpdateSingleItem(SingletonName string, newData map[string]any) (*models.SingleItem, error)

UpdateSingleItem updates the SingleItem for a given single type with new data. Returns the updated SingleItem or an error if not found or validation fails.

func UpdateUser

func UpdateUser(id uint, updates map[string]interface{}) error

UpdateUser updates the details of an existing user by ID.

Types

type DBToolCall

type DBToolCall struct {
	ID           string `json:"id"`
	Type         string `json:"type"`
	FunctionName string `json:"function_name"`
	Arguments    string `json:"arguments"`
}

DBToolCall represents a simplified tool call for database storage

type DuplicateEntryError

type DuplicateEntryError struct {
	Field string
}

Custom error types

func (*DuplicateEntryError) Error

func (e *DuplicateEntryError) Error() string

type GeneralDatabaseError

type GeneralDatabaseError struct {
	Message string
}

func (*GeneralDatabaseError) Error

func (e *GeneralDatabaseError) Error() string

type ItemFilter

type ItemFilter struct {
	Field string
	Op    string
	Value string
}

ItemFilter is one condition on an item attribute (or a built-in column).

type ItemQuery

type ItemQuery struct {
	Page     int
	PageSize int
	Filters  []ItemFilter
	Sort     []ItemSort
}

ItemQuery describes a filtered, sorted, paginated item listing.

type ItemSort

type ItemSort struct {
	Field string
	Desc  bool
}

ItemSort orders results by an attribute or a built-in column.

type ItemValidationError

type ItemValidationError struct {
	Index int // position in a batch; 0 for single saves
	Err   error
}

ItemValidationError wraps a validation failure for an item, as opposed to a database error, so callers can answer 400 instead of 500.

func (*ItemValidationError) Error

func (e *ItemValidationError) Error() string

func (*ItemValidationError) Unwrap

func (e *ItemValidationError) Unwrap() error

type QueryFieldError

type QueryFieldError struct{ Msg string }

QueryFieldError reports a filter or sort the collection cannot satisfy.

func (*QueryFieldError) Error

func (e *QueryFieldError) Error() string

Jump to

Keyboard shortcuts

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