Skip to main content
Collections and settings are easy to mix up at first because they both store data. The difference is simpler than it sounds. Collections hold the records your app works on. Settings hold the knobs people use to control how the app behaves. Once that distinction clicks, the rest of the page reads much more naturally.

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:
Here the collection holds the workflow records and the settings hold operator preferences. That is the split most apps want. Capsule collections support four scopes: A practical way to read the scopes:
  • app for a shared lead table
  • user for saved bookmarks for one user of this app
  • owner for organization-wide reports
  • session for 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

  • text
  • number
  • currency
  • date
  • link
  • email
  • status
  • tags
  • boolean

Column fields

Example collection declaration:

CollectionRef

CollectionRef is returned by app.collection(...).

Common methods

Inserted documents get both _id and id. Typical CRUD flow:

Update behavior

Plain update dicts are treated as patches and automatically wrapped in $set:
Operator documents pass through unchanged:
Do not mix plain keys and operator keys in one update document.

session.db

Inside a live session, session.db gives you scoped collection access:
This is especially convenient for user, owner, and session collections, where the live session already knows which scope to use. Example:

Settings declarations

Declare settings with app.setting(...):

Arguments

A fuller example:

app.settings

The settings accessor methods are async:
Settings are stored in a reserved backing collection and scoped using the same identity rules as collections. In practice, you mostly notice this because settings and pages fit together cleanly:

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. Use session.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.

See also