Generate data-access-objects from your domain-objects.
npm install dynamodb-dao-generatorGenerate data-access-objects from your domain-objects.
Generates type definitions, query functions, terraform resources, and bundles it all up into daos with a single command!





dynamodb-dao-generator generatedynamodb-dao-generator help [COMMAND]](#dynamodb-dao-generator-help-command)The goal of dynamodb-dao-generator is to use the domain-objects you've already defined in order to speed up development and eliminate errors.
Powered by:
- extracting the domain information you've already encoded in your domain-objects using domain-objects-metadata.
This enables:
- creating a fully functional data-access-object, using best practices, simply by defining your domain-objects
- easily extending your generated data-access-objects, because you control the code completely
- instantly leveraging the best practices and safety features finetuned against countless deployments in production
Like an ORM, but without any magic or limitations - the code is in your hands and ready to mod as needed.
sh
npm install --save-dev dynamodb-dao-generator
`2. Define a config file
This file will define which
domain-objects you want to generate data-access-objects forFor example:
`ts
// codegen.dynamodb.dao.tsimport {
DeclaredDaoSpecification,
DeclaredDomainObjectIntrospectionPaths,
DeclaredOutputDirectories,
} from 'dynamodb-dao-generator';
import { Sensor, Address } from './src/domain';
export const introspect: DeclaredDomainObjectIntrospectionPaths = [
'./src/domain/index.ts',
];
export const directories: DeclaredOutputDirectories = {
terraform:
provision/aws/product,
dao: src/data/dao,
};export const specifications: DeclaredDaoSpecification[] = [
{
domainObject: Sensor,
supplementalIndexes: [
{ filterByKey: ['addressUuid'] },
{ filterByKey: ['ownerUuid'], sortByKey: ['createdAt'] },
],
},
{
domainObject: Address,
supplementalIndexes: [
{ filterByKey: ['city', 'state'] },
{ filterByKey: ['postal'] },
],
},
];
`3. Test it out!
`
$ npx dynamodb-dao-generator version
$ npx dynamodb-dao-generator generate
`Examples
$3
Input: Say you have the following domain object
`ts
export interface Geocode {
id?: number;
latitude: number;
longitude: number;
}
export class Geocode extends DomainLiteral implements Geocode {}
`Output: Running this dynamodb-dao-generator on this domain object will:
1. generate the dao files
1.
src/data/dao/geocodeDao/index.ts
2. src/data/dao/geocodeDao/findByUuid.ts
3. src/data/dao/geocodeDao/findByUnique.ts
4. src/data/dao/geocodeDao/castToDatabaseObject.ts
5. src/data/dao/geocodeDao/castFromDatabaseObject.ts
6. src/data/dao/geocodeDao/.maintenance/migrateAllRecordsToNewSchema.ts2. generate the terraform table provisioning file
1.
provision/aws/product/dynamodb.table.geocode.tf
Commands
* dynamodb-dao-generator generate
* [dynamodb-dao-generator help [COMMAND]](#dynamodb-dao-generator-help-command)dynamodb-dao-generator generategenerate data-access-objects by parsing domain-objects
`
USAGE
$ dynamodb-dao-generator generateOPTIONS
-c, --config=config (required) [default: codegen.sql.dao.yml] path to config yml
-h, --help show CLI help
`_See code: dist/contract/commands/generate.ts_
dynamodb-dao-generator help [COMMAND]display help for dynamodb-dao-generator
`
USAGE
$ dynamodb-dao-generator help [COMMAND]ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
``_See code: @oclif/plugin-help_
Team work makes the dream work! Please create a ticket for any features you think are missing and, if willing and able, draft a PR for the feature :)