dynamodb-dao-generator
v1.1.0
Published
Generate data-access-objects from your domain-objects.
Downloads
74
Maintainers
Readme
dynamodb-dao-generator
Generate 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!
Table of Contents
Goals
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.
Installation
1. Save the package as a dev dependency
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
for
For example:
// codegen.dynamodb.dao.ts
import {
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
a domain object dao
Input: Say you have the following domain object
export interface Geocode {
id?: number;
latitude: number;
longitude: number;
}
export class Geocode extends DomainLiteral<Geocode> implements Geocode {}
Output: Running this dynamodb-dao-generator on this domain object will:
generate the dao files
src/data/dao/geocodeDao/index.ts
src/data/dao/geocodeDao/findByUuid.ts
src/data/dao/geocodeDao/findByUnique.ts
src/data/dao/geocodeDao/castToDatabaseObject.ts
src/data/dao/geocodeDao/castFromDatabaseObject.ts
src/data/dao/geocodeDao/.maintenance/migrateAllRecordsToNewSchema.ts
generate the terraform table provisioning file
provision/aws/product/dynamodb.table.geocode.tf
Commands
dynamodb-dao-generator generate
generate data-access-objects by parsing domain-objects
USAGE
$ dynamodb-dao-generator generate
OPTIONS
-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
Contribution
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 :)