Module: Dynamoid::CDK::Schema

Defined in:
lib/dynamoid/cdk/schema.rb,
lib/dynamoid/cdk/schema.rb,
lib/dynamoid/cdk/schema/version.rb,
lib/dynamoid/cdk/schema/descriptor.rb,
lib/dynamoid/cdk/schema/introspector.rb,
lib/dynamoid/cdk/schema/table_builder.rb,
sig/dynamoid/cdk/schema.rbs

Overview

Generate AWS CDK DynamoDB tables straight from your Dynamoid models, so the models are the single source of truth for keys and indexes and the two can't drift.

Defined Under Namespace

Modules: Introspector, TableBuilder Classes: Attribute, Descriptor, Error, Index

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.1.0"

Class Method Summary collapse

Class Method Details

.describe(model) ⇒ Object

The model's table shape as plain data (a Descriptor). Needs only Dynamoid — handy for inspection, tests, or feeding another tool.



27
28
29
# File 'lib/dynamoid/cdk/schema.rb', line 27

def describe(model)
  Introspector.call(model)
end

.table(scope, id, model, **table_props) ⇒ Object

Build and return a CDK TableV2 for model in scope under id. Any extra keyword arguments pass straight through to TableV2 (e.g. removal_policy:, billing:, point_in_time_recovery:), so the model owns keys and indexes while the caller owns table-level configuration. Requires aws-cdk-lib to be loaded.

Dynamoid::CDK::Schema.table(self, "Posts", Post, removal_policy: ...)


38
39
40
# File 'lib/dynamoid/cdk/schema.rb', line 38

def table(scope, id, model, **table_props)
  TableBuilder.build(scope, id, describe(model), **table_props)
end