Suppose I have a already existing table in DynamoDB, how do I register it with PocoDynamo
The type "SomeTable" points to different tables in prod and stg environments. Is there a way to register the type with table name or set the table name some other way.
_pocoClient.PutItem<SomeTable>(item)
Is there a way to use existing table with PocoDynamo ?
Note: I create tables using terraform, dont want to use PocoDynamo to create infra.
In PocoDynamo you just need to call RegisterTable
to "register" the table and its schema with PocoDynamo, i.e:
db.RegisterTable<SomeTable>();
You can programmatically change the table name (On Startup before calling InitSchema()) by registering the table with:
var metadata = DynamoMetadata.RegisterTable<SomeTable>();
metadata.Name = "DbTableName";
After registering and configuring tables, calling InitSchema
will only create the tables that don't already exist:
db.InitSchema();
If you want the DynamoDB Table to have a different Name than the .NET Type name you can use the Alias attribute, e.g:
[Alias("DbTableName")]
public class SomeTable
{
//..
}
Note: PocoDynamo is a code-first typed .NET client meaning that it expects the DynamoDB Tables to be created exactly how it would create it, it's not useful for mapping to existing tables generated with different conventions.