Skip to content
Back to top
View this page

# Attachments

Attachments connect values to documents via keys. They are the fundamental mechanism for associating typed data with document instances.

When to use: Use attachments to store and retrieve values associated with document keys. The `AttachmentGetting` interface provides read access, while `AttachmentMutating` extends it with write operations.

## Quick Start

    from dsviper import CommitDatabase, CommitMutableState

    db = CommitDatabase.open("model.cdb")
    db.definitions().inject()

    # Read via AttachmentGetting
    state = db.state(db.last_commit_id())
    getting = state.attachment_getting()
    value = getting.get(MYAPP_A_USER, user_key)

    # Write via AttachmentMutating
    mutable = CommitMutableState(state)
    mutating = mutable.attachment_mutating()
    mutating.set(MYAPP_A_USER, user_key, document)

## Core Classes

`dsviper.Attachment` | A class used to represent an attachment.

## Attachment Interfaces

These interfaces provide read (getting) and write (mutating) access to attached values.

`dsviper.AttachmentGetting` | An interface used to retreive a value (aka document) state.
`dsviper.AttachmentMutating` | An interface used to express fine-grained mutations of a value.

## Attachment Functions

User-defined functions that operate on attached values, defined via DSM.

`dsviper.AttachmentGettingFunction` | A class used to call a C++ function.
`dsviper.AttachmentMutatingFunction` | A class used to call a mutable function.
`dsviper.AttachmentFunctionPool` | A class used to register and retrieve C++ attachment function.
`dsviper.AttachmentFunctionPoolFunctions` | A class used to represent the functions of a pool.