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 ¶
- type Filter
- type FilterSet
- type TxManager
- func (tx *TxManager) Delete(dt *doctype.DocType, name string, owner string) error
- func (tx *TxManager) GetDoc(dt *doctype.DocType, name string, owner string) (*doctype.Document, error)
- func (tx *TxManager) GetList(dt *doctype.DocType, filters string, orderBy string, limit, offset int, ...) ([]*doctype.Document, int, error)
- func (tx *TxManager) Insert(dt *doctype.DocType, doc *doctype.Document, owner, modifiedBy string) error
- func (tx *TxManager) Save(dt *doctype.DocType, doc *doctype.Document, modifiedBy string, owner string, ...) error
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 ¶
ParseFilters parses a JSON-encoded filter array. Format: [["field","=","value"],["field2",">",5]]
func (*FilterSet) ToSQL ¶
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 ¶
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 ¶
TxManager provides transactional operations on documents.
func (*TxManager) Delete ¶
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.