orm

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 11 Imported by: 0

Documentation

Overview

Package orm — filter parsing utilities.

Package orm provides the generic ORM layer for Kora. All documents are represented as doctype.Document (map[string]any).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter [3]any

Filter represents a single filter condition: [field, operator, value].

type FilterSet

type FilterSet struct {
	Filters []Filter
}

FilterSet is a collection of filters applied together.

func ParseFilters

func ParseFilters(raw string) (*FilterSet, error)

ParseFilters parses a JSON-encoded filter array. Format: [["field","=","value"],["field2",">",5]]

func (*FilterSet) ToSQL

func (fs *FilterSet) ToSQL() (string, []any, error)

ToSQL converts the filter set to a SQL WHERE clause and arguments. Returns the WHERE clause string (without "WHERE") and the argument slice.

func (*FilterSet) ValidateFields

func (fs *FilterSet) ValidateFields(dt *doctype.DocType) error

ValidateFields checks that all filter field names are valid columns in the DocType. This prevents SQL injection via user-supplied field names in filter clauses. System columns (name, owner, creation, modified, modified_by, doc_status, idx) and all data fields are considered valid.

type TxManager

type TxManager struct {
	DB       *sql.DB
	Registry *doctype.Registry
	Dialect  db.Dialect
}

TxManager provides transactional operations on documents.

func (*TxManager) Delete

func (tx *TxManager) Delete(dt *doctype.DocType, name string, owner string) error

Delete removes a document by name. If owner is non-empty, only deletes if the document is owned by that user.

func (*TxManager) GetDoc

func (tx *TxManager) GetDoc(dt *doctype.DocType, name string, owner string) (*doctype.Document, error)

GetDoc loads a single document by name, including child table expansion. If owner is non-empty, only returns the document if owned by that user.

func (*TxManager) GetList

func (tx *TxManager) GetList(dt *doctype.DocType, filters string, orderBy string, limit, offset int, owner string) ([]*doctype.Document, int, error)

GetList returns a paginated list of documents with optional filtering. If owner is non-empty, only returns documents owned by that user.

func (*TxManager) Insert

func (tx *TxManager) Insert(dt *doctype.DocType, doc *doctype.Document, owner, modifiedBy string) error

Insert creates a new document in the database. modifiedBy is stored in the modified_by column — use the actor responsible (e.g., user or "ai-assistant").

func (*TxManager) Save

func (tx *TxManager) Save(dt *doctype.DocType, doc *doctype.Document, modifiedBy string, owner string, oldDoc *doctype.Document) error

Save updates an existing document. If owner is non-empty, only updates if the document is owned by that user. All operations run in a database transaction to ensure atomicity. oldDoc is the document before modifications (from GetDoc); when provided, child table reconciliation uses a diff-based approach instead of DELETE-all + re-INSERT-all.

Jump to

Keyboard shortcuts

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