Features

Lifecycle Timestamps

created_at and updated_at are the canonical lifecycle timestamp roles. They identify the creation and last-update attributes in the model contract. Go, TypeScript, and Python populate these fields in their shared P0 write paths:

  • opt-in only. A field is managed when it carries the role — Go theorydb:"created_at", TypeScript roles: ['created_at'], Python roles=["created_at"]. Nothing is inferred from a field or attribute name, so a column that is called CreatedAt but was never opted in belongs to your model and is stored exactly as you set it;
  • create/save writes populate created_at and updated_at with the same write timestamp;
  • created_at is written once per item. A write of an item that already stores a creation time keeps the stored value, whatever value the caller hands the write — the original model, a modified copy, a rebuild from a literal, a reload, or a value that carries no creation time at all;
  • update writes preserve created_at and advance updated_at;
  • a failed conditional update does not advance updated_at;
  • managed timestamps are stored in UTC. The value written is the RFC3339Nano text of the instant in UTC — 2026-01-02T03:04:05.000000001Z, never 2026-01-02T05:04:05.000000001+02:00. The spelling of an instant therefore depends only on the instant, so a DynamoDB string condition over a lifecycle attribute compares instants, and a row written by a Lambda function in UTC is comparable with one written by a developer’s machine in another zone. A value your model supplies for created_at is stored verbatim: the runtime does not re-spell a timestamp you set yourself.

Removing name-based inference in Go was a breaking change with a migration note; see the v7 migration guide.

The update rule includes model-shaped explicit-field transaction updates: Go TransactionBuilder.Update, TypeScript item + fields transaction actions, and Python TransactUpdate. Raw expressions and update-builder callbacks are low-level escape hatches and mutate lifecycle fields only when the caller asks.

The lifecycle P0 fixture tracks the shared contract shape and expected timestamp ordering across all three runtimes.

Go

type Note struct {
    PK        string    `theorydb:"pk"          json:"pk"`
    SK        string    `theorydb:"sk"          json:"sk"`
    Body      string    `json:"body"`
    CreatedAt time.Time `theorydb:"created_at"  json:"created_at"`
    UpdatedAt time.Time `theorydb:"updated_at"  json:"updated_at"`
}

n := &Note{PK: "USER#1", SK: "NOTE#welcome", Body: "Hi."}
db.Model(n).Create()
// n.CreatedAt and n.UpdatedAt are populated by the Go runtime.

TypeScript

const Note = defineModel({
  name: 'Note',
  table: { name: 'notes_contract' },
  keys: {
    partition: { attribute: 'PK', type: 'S' },
    sort:      { attribute: 'SK', type: 'S' },
  },
  attributes: [
    { attribute: 'PK',        type: 'S', roles: ['pk'] },
    { attribute: 'SK',        type: 'S', roles: ['sk'] },
    { attribute: 'body',      type: 'S' },
    { attribute: 'createdAt', type: 'S', roles: ['created_at'] },
    { attribute: 'updatedAt', type: 'S', roles: ['updated_at'] },
  ],
});

await db.create('Note', { PK: 'USER#1', SK: 'NOTE#welcome', body: 'Hi.' });
// createdAt and updatedAt are written by the TypeScript runtime.

Python

@dataclass(frozen=True)
class Note:
    pk:         str = theorydb_field(name="PK", roles=["pk"])
    sk:         str = theorydb_field(name="SK", roles=["sk"])
    body:       str = theorydb_field()
    created_at: str = theorydb_field(name="createdAt", roles=["created_at"], default="")
    updated_at: str = theorydb_field(name="updatedAt", roles=["updated_at"], default="")
    version:    int = theorydb_field(roles=["version"], default=0)

model = ModelDefinition.from_dataclass(Note, table_name="notes_contract")
table = Table(model, client=client)

table.put(Note(
    pk="USER#1",
    sk="NOTE#welcome",
    body="Hi.",
))

note = table.get("USER#1", "NOTE#welcome")
table.update(
    "USER#1",
    "NOTE#welcome",
    {"body": "Edited."},
    expected_version=note.version,
)

Composes with optimistic locking

On successful versioned writes, updated_at advances alongside the version role. A version conflict aborts the write — neither version nor updated_at advances. In Python, pass expected_version= to Table.update for this high-level guarded update shape.

Composes with TTL

updated_at does not influence the TTL attribute. TTL is computed from the field with the ttl role, independent of when the item was last touched. If you want “extend TTL on every write,” update the TTL field explicitly in your write path.

Set once is a property of the write

A DynamoDB PutItem replaces the whole item, and a batch or transactional put does the same. None of them can observe the creation time it is about to overwrite on its own — so the runtime resolves it before every put, on every put path, and stores the resolved value:

  1. a value that carries a creation time carries that item’s creation time, and is stored verbatim;
  2. a value that carries none — a modified copy, a rebuild from a literal, a reload of a partial value, a value this runtime never saw — stores the creation time the item already stores, read consistently and projected to that one attribute;
  3. only a write the item does not answer for (the write that creates it) takes this write’s clock.

Because the rule lives in the write, it holds for any object: nothing depends on the object’s identity, equality or hash. That matters most in Python, where a model is frequently a frozen dataclass the runtime must never mutate.

The resolution is one small consistent read per managed write that carries no creation time — batched when a transaction holds several such writes (see below). A managed write whose stored creation time cannot be read fails rather than inventing one: refusing the write keeps the item’s creation time intact, while guessing would move it.

Transactional puts read their creation times together

A transaction can hold 100 puts, and each one that carries no creation time has a creation time to keep. Go and TypeScript therefore resolve them for the whole transaction in one BatchGetItem, chunked at its 100-key limit with unprocessed keys retried, instead of one GetItem per put; Python reads them the same way. A 54-put transaction — an admission re-holding 54 claims — costs one round trip before TransactWriteItems rather than 54, so a caller’s deadline is spent on the commit instead of on pre-reads.

Those reads are inside the execute context. In Go the context passed to ExecuteWithContext (or the one set with WithContext) carries the deadline and cancellation into them, and in TypeScript the send options carry the abort signal; a context that has already ended fails the write before any request leaves the process, and one that ends while the reads are waiting out an unprocessed-key backoff settles the write there. Python’s transaction API is synchronous and carries no context, so it takes the batching half of the rule only.

Two properties of those reads decide whether an existing creation time survives:

  • A key is matched by value, not by spelling. DynamoDB stores Number attribute values in a canonical form and answers in that form, so a key spelled Decimal('3.0') in Python, 1e+21 in TypeScript or 3 in Go names the item stored as 3. The response item is matched back to every put that names it by comparing the number’s value (and strings and binary values exactly). Matching the rendered text instead finds no item, which reads as “this write creates the item” and stamps the clock over a stored creation time.
  • A key is asked for once. Two puts on one key are two writes of one item, which TransactWriteItems rejects on its own; BatchGetItem refuses duplicate keys, so the read deduplicates its request and lets the write own that rejection. One answer serves both puts.

updated_at takes this write’s clock on every one of these paths.

Frozen models: use the value put returns

Go writes the stored lifecycle values back into the model struct and TypeScript into the caller’s object, so the value you already hold carries them. A frozen Python dataclass cannot be mutated, so Table.put (and save) return the value that carries what was stored:

stored = table.put(Note(pk="USER#1", sk="NOTE#welcome", body="Hi."))
stored.created_at  # the creation time the write stored

# Keep using the returned value for the next write of the same item.
table.put(replace(stored, body="Edited."))

Passing a value that carries nothing is still safe — the write resolves the stored creation time — but the returned value is what makes the caller’s own state agree with what is stored.

What this does not change

  • a managed write still replaces the whole item, so use the conditional create (Create() / ifNotExists) when write-once must be guaranteed rather than observed;
  • a value that supplies its own creation time on the creating write keeps it verbatim, which is what makes importing existing data possible;
  • an update never touches created_at at all, so it cannot move it.

Anti-patterns

  • Don’t set created_at or updated_at manually in high-level create/update paths. The runtime owns lifecycle fields on those paths; caller-supplied lifecycle timestamp fields are rejected on update rather than written through.
  • Don’t rename a column to dodge the runtime. A field named CreatedAt is not managed unless you tag it; renaming to RowCreatedAt was only ever necessary while inference existed.
  • Don’t rely on created_at for tie-breaking equal-version writes. Use the version role; that’s what it’s for.
  • Optimistic Locking — the version field that composes with these timestamps
  • TTL — separate timestamp axis governed by its own role
  • Contract Scenarios — the full lifecycle-timestamps specification