Collection scopes
Collections and settings are related, but they solve different problems:- collections are for records
- settings are for configuration
Worked example
This is a common production shape:| Scope | Meaning |
|---|---|
app | Shared across the whole app |
user | Isolated per authenticated app user |
owner | Shared across an owner or organization |
session | Isolated to a single session |
appfor a shared lead tableuserfor saved bookmarks for one user of this appownerfor organization-wide reportssessionfor temporary scratch notes
cpsl.Column
Use cpsl.Column when the table needs more than a bare field name. It lets you tell Capsule how a column should be understood and rendered.
Supported column types
textnumbercurrencydatelinkemailstatustagsboolean
Column fields
| Field | Meaning |
|---|---|
key | Stored field name |
type | Column type |
label | Optional display label |
format | Optional display formatting hint |
CollectionRef
CollectionRef is returned by app.collection(...).
Common methods
| Method | Purpose |
|---|---|
insert_one(document) | Insert one document |
insert_many(documents) | Insert multiple documents |
find_one(filter=None) | Find one document |
find(filter=None, limit=0, skip=0, sort=None) | Query many documents |
update_one(filter, update) | Patch one document |
delete_one(filter) | Delete one document |
count(filter=None) | Count matching documents |
_id and id.
Typical CRUD flow:
Update behavior
Plain update dicts are treated as patches and automatically wrapped in$set:
session.db
Inside a live session, session.db gives you a scoped database proxy:
user, owner, and session collections, where the live session already knows which scoped database it should be talking to.
Example:
Settings declarations
Declare settings withapp.setting(...):
Arguments
| Argument | Meaning |
|---|---|
name | Unique setting key |
scope | app, owner, or user |
type | bool, str, int, or float |
default | Default value when unset |
options | Allowed values for select-like settings |
label | Human-readable UI label |
app.settings
The settings accessor methods are async:
Practical guidance
Use collections for records the app needs to query later. Use settings for configuration that users or operators should be able to tweak. Usesession.data for conversational scratch state that only matters inside the current session. Add typed Column metadata when the table needs richer rendering or clearer labels.