npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamodb-dao-generator

v1.0.8

Published

Generate data-access-objects from your domain-objects.

Downloads

463

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!

oclif Version Codecov Downloads/week License

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:

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 DomainValueObject<Geocode> 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.ts
  2. generate the terraform table provisioning file

    1. 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 :)