tabletheory

package module
v1.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 15

README

TableTheory

TableTheory

DynamoDB-first multi-language data contract.
One specification. Three runtimes. Verified on every commit.

Release License Docs Quality gates CodeQL

Go TypeScript Python

Get started → · API reference · Contract scenarios · DMS spec


TableTheory is a DynamoDB-first ORM and schema contract designed to keep data access consistent across languages and reliable in generative coding workflows (humans + AI assistants). It ships peer implementations in Go, TypeScript, and Python — not a Go library with bindings, but three independent runtimes that pass the same P0 contract scenarios on every commit.

            FaceTheory (client delivery)
                      │
            AppTheory (serverless runtime)
                      │
      TableTheory (data layer)  ← you are here
                      │
                  DynamoDB

TableTheory is the foundation of the Theory Cloud stack — used in production by Pay Theory.

Install

TableTheory is distributed exclusively through immutable GitHub Releases — no PyPI, no npm. The single distribution path keeps versions aligned across all three runtimes.

Runtime Install
Go go get github.com/theory-cloud/tabletheory@vX.Y.Z
TypeScript install the npm pack release asset — see TypeScript getting started
Python install the wheel/sdist release asset — see Python getting started

At a glance

P0 contract scenarios 9 — CRUD, omit-empty, lifecycle, locking, TTL, and release-state fixtures
Runtimes Go · TypeScript · Python (peers, not ports)
Distribution Immutable GitHub Releases — version-aligned across all runtimes
License Apache-2.0 — open source, production use
Status Post-1.0 stable API across all three runtimes

Why TableTheory?

Use TableTheory when you want DynamoDB-backed systems that are:

  • Serverless-first — patterns that work well in AWS Lambda: cold-start aware LambdaInit, batching with Lambda timeout awareness, transactions, streams, optional KMS-backed field encryption that's fail-closed by design.
  • Cross-language consistent — one table, multiple services, multiple runtimes — without schema or behavior drift. Verified on every commit by the P0 contract scenarios.
  • Generative-coding friendly — explicit schema, canonical patterns, and strict verification so AI-generated code stays correct and maintainable.

✅ Treat schema + semantics as a contract ❌ Don't redefine "the same" table shape independently per service/language

Documentation

The full documentation site lives at tabletheory.theorycloud.ai — branded with the Theory Cloud design system, with a ⌘K search palette, runtime tabs, and surface-tinted pages.

Most-used entry points:

Section Link
Getting started tabletheory.theorycloud.ai/getting-started/
API reference tabletheory.theorycloud.ai/api-reference/
Struct definition guide tabletheory.theorycloud.ai/struct-definition-guide/
Core patterns tabletheory.theorycloud.ai/core-patterns/
Architecture patterns tabletheory.theorycloud.ai/architecture-patterns/
Testing tabletheory.theorycloud.ai/testing-guide/
Troubleshooting tabletheory.theorycloud.ai/troubleshooting/

Per-runtime entry points:

P0 contract reference and related feature pages:

Integrations — how downstream Theory Cloud frameworks use TableTheory:

Repository layout

Path What
docs/ Public documentation site (Jekyll) — also the canonical doc tree
ts/ TypeScript SDK — TS docs index
py/ Python SDK — Py docs index
contract-tests/ Cross-language P0 fixtures + runners
examples/cdk-multilang/ Deployable demo: one DynamoDB table, three Lambdas (Go, Node.js 24, Python 3.14)
.github/workflows/ CI: rubric, language gates, release-please, Pages publish

Serverless data demo (CDK)

The CDK demo deploys one DynamoDB table + three Lambda Function URLs (Go, Node.js 24, Python 3.14) that read/write the same item shape and exercise portability-sensitive features (encryption, batching, transactions):

examples/cdk-multilang/README.md

For infrastructure patterns, see the CDK integration guide.

DMS — the language-neutral schema

TableTheory's drift-prevention story centers on a shared, language-neutral schema document: TableTheory Spec (DMS).

dms_version: "0.1"
models:
  - name: "Note"
    table: { name: "notes_contract" }
    keys:
      partition: { attribute: "PK", type: "S" }
      sort:      { attribute: "SK", type: "S" }
    attributes:
      - { attribute: "PK",    type: "S", required: true, roles: ["pk"] }
      - { attribute: "SK",    type: "S", required: true, roles: ["sk"] }
      - { attribute: "value", type: "N" }

DMS is authored independently of any runtime — Go, TypeScript, and Python all validate against the same spec. See the DMS Specification v0.1 for the public summary.

Development & verification

make rubric        # full repo verification (the all-gates gate)
make docker-up     # start DynamoDB Local
make test          # full suite incl. integration

For multi-language work:

cd ts && npm run lint && npm run typecheck && npm run test:unit
uv --directory py run pytest -q tests/unit

See CONTRIBUTING.md for full contributor docs, including the Authoring documentation section if you're updating the docs site.

Theory Cloud

TableTheory is the data foundation of the Theory Cloud stack. Nothing in Theory Cloud precedes it.

  • AppTheory (serverless runtime) → depends on TableTheory
  • FaceTheory (client delivery) → depends on TableTheory
  • KnowledgeTheory (platform state + knowledge graph) → depends on TableTheory
  • Autheory (identity) → depends on TableTheory
  • theory-mcp-server → depends on TableTheory

The single-path philosophy starts here: one way to define a table, one way to access data, one way to handle encryption — enforced by the framework, not by convention. When generative coding tools produce TableTheory code, the constrained API surface means the output converges on correct implementations instead of drifting across equivalent-but-incompatible patterns.

License & contributing

Made with Theory Cloud · docs

Documentation

Overview

Package tabletheory provides a type-safe ORM for Amazon DynamoDB in Go.

Import path:

import "github.com/theory-cloud/tabletheory"

Implementation lives in `internal/theorydb` so the repo root stays minimal.

Index

Constants

This section is empty.

Variables

View Source
var (
	WithBackupTable = schema.WithBackupTable
	WithDataCopy    = schema.WithDataCopy
	WithTargetModel = schema.WithTargetModel
	WithTransform   = schema.WithTransform
	WithBatchSize   = schema.WithBatchSize
)

Re-export AutoMigrate options for convenience.

Functions

func AtVersion

func AtVersion(version int64) core.TransactCondition

func Condition

func Condition(field, operator string, value any) core.TransactCondition

func ConditionExpression

func ConditionExpression(expression string, values map[string]any) core.TransactCondition

func ConditionVersion

func ConditionVersion(version int64) core.TransactCondition

func DefaultBatchGetOptions

func DefaultBatchGetOptions() *core.BatchGetOptions

func EnableXRayTracing

func EnableXRayTracing() bool

func GetLambdaMemoryMB

func GetLambdaMemoryMB() int

func GetPartnerFromContext

func GetPartnerFromContext(ctx context.Context) string

func GetRemainingTimeMillis

func GetRemainingTimeMillis(ctx context.Context) int64

func IfExists

func IfExists() core.TransactCondition

func IfNotExists

func IfNotExists() core.TransactCondition

func IsLambdaEnvironment

func IsLambdaEnvironment() bool

func New

func New(config session.Config) (core.ExtendedDB, error)

func NewBasic

func NewBasic(config session.Config) (core.DB, error)

func NewKeyPair

func NewKeyPair(partitionKey any, sortKey ...any) core.KeyPair

func PartnerContext

func PartnerContext(ctx context.Context, partnerID string) context.Context

func UnmarshalItem

func UnmarshalItem(item map[string]types.AttributeValue, dest interface{}) error

func UnmarshalItems

func UnmarshalItems(items []map[string]types.AttributeValue, dest interface{}) error

func UnmarshalStreamImage

func UnmarshalStreamImage(streamImage map[string]events.DynamoDBAttributeValue, dest interface{}) error

Types

type AccountConfig

type AccountConfig = internaltheorydb.AccountConfig

type AutoMigrateOption

type AutoMigrateOption = schema.AutoMigrateOption

type BatchGetOptions

type BatchGetOptions = core.BatchGetOptions

type ColdStartMetrics

type ColdStartMetrics = internaltheorydb.ColdStartMetrics

func BenchmarkColdStart

func BenchmarkColdStart(models ...any) ColdStartMetrics

type Config

type Config = session.Config

Re-export types for convenience.

type DB

type DB = internaltheorydb.DB

type KeyPair

type KeyPair = core.KeyPair

type LambdaDB

type LambdaDB = internaltheorydb.LambdaDB

func LambdaInit

func LambdaInit(models ...any) (*LambdaDB, error)

func NewLambdaOptimized

func NewLambdaOptimized() (*LambdaDB, error)

type LambdaMemoryStats

type LambdaMemoryStats = internaltheorydb.LambdaMemoryStats

type LambdaTimeoutConfig added in v1.8.0

type LambdaTimeoutConfig = internaltheorydb.LambdaTimeoutConfig

type MultiAccountDB

type MultiAccountDB = internaltheorydb.MultiAccountDB

func NewMultiAccount

func NewMultiAccount(accounts map[string]AccountConfig) (*MultiAccountDB, error)

Directories

Path Synopsis
Package examples demonstrates TableTheory's embedded struct support
Package examples demonstrates TableTheory's embedded struct support
encryption command
initialization command
Package main demonstrates proper TableTheory initialization patterns to avoid nil pointer dereference errors
Package main demonstrates proper TableTheory initialization patterns to avoid nil pointer dereference errors
lambda command
optimization command
release-state command
internal
theorydb
lambda.go
lambda.go
pkg
consistency
Package consistency provides utilities for handling eventual consistency in DynamoDB
Package consistency provides utilities for handling eventual consistency in DynamoDB
core
Package core defines the core interfaces and types for TableTheory
Package core defines the core interfaces and types for TableTheory
dms
errors
Package errors defines error types and utilities for TableTheory
Package errors defines error types and utilities for TableTheory
interfaces
Package interfaces provides abstractions for AWS SDK operations to enable mocking
Package interfaces provides abstractions for AWS SDK operations to enable mocking
lease
Package lease provides a small, correctness-first DynamoDB lease/lock helper.
Package lease provides a small, correctness-first DynamoDB lease/lock helper.
marshal
Package marshal provides optimized marshaling for DynamoDB
Package marshal provides optimized marshaling for DynamoDB
mocks
Package mocks provides mock implementations for TableTheory interfaces and AWS SDK operations
Package mocks provides mock implementations for TableTheory interfaces and AWS SDK operations
model
Package model provides model registration and metadata management for TableTheory
Package model provides model registration and metadata management for TableTheory
query
Package query provides aggregate functionality for DynamoDB queries
Package query provides aggregate functionality for DynamoDB queries
releasestate
Package releasestate contains opt-in helpers for release-state registry records.
Package releasestate contains opt-in helpers for release-state registry records.
session
Package session provides AWS session management and DynamoDB client configuration
Package session provides AWS session management and DynamoDB client configuration
testing
Package testing provides utilities for testing applications that use TableTheory.
Package testing provides utilities for testing applications that use TableTheory.
transaction
Package transaction provides atomic transaction support for TableTheory
Package transaction provides atomic transaction support for TableTheory
types
Package types provides type conversion between Go types and DynamoDB AttributeValues
Package types provides type conversion between Go types and DynamoDB AttributeValues
scripts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL