Code Monkey home page Code Monkey logo

sads.js's Introduction

sads.js - Simple Application Data Service

Nest Logo Dynamo Logo

Build your fully functional RESTful server within 20 minutes!

based on NestJS and DynamoDB

Benefits from sads.js

With sads.js, you could provide powerful RESTful APIs in 20 minutes.

With sads.js, you don't have to start your projects with well-designed E-R diagrams and database designs. You don't have to log into the database manager and update database schemas and you don't have to run database migrations. You could easily change the database schemas because there are no physical schemas at all.

In summary, you could spend as less as possible on back-end and put more efforts on front-end design so that clients can see the scooter, the bicycle as early as possible.

How less do you have to work on back-end in the early stages (before motorbike) of the project?

  • 20 minutes to start;
  • 5-10 minutes for every new change;
  • 2-3 days IN TOTAL

Applicable Scenarios

In principle, sads.js is applicable to the scenarios of

  • Small scale data storage (no more than thousands) & medium level of complexity of entity relationships
  • Large scale data storage with very simple entity relationships
  • The data in the past are not allowed (or unnecessary) to be changed

Therefore, sads.js is pretty good at building scrum projects which started normally with only a couple of concepts without any detailed requirements, just like:

  • Projects for PoC (Proof of Concept)
  • Personal projects (normally with very small data storage)

Quick Start

Installation

$ npm install

Setup local DynamoDB

please refer to dynamodb/README.md

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

then launch your browser and navigate to the Swagger UI: http://localhost:3000/api

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Database Design Principles

1. Conceptually, use 'Entity' in E-R Diagrams for 'Tables' to avoid confusions

2. Every entity must contains fields pk and sk

3. The field pk

  • is used as id (just like in RDBMS),
  • should be a string BUT NOT AN INTEGER;
  • contains a guid/uuid string;

4. The field sk

  • is used as the entity name;
  • should be a string in the format of "appName(optional) + entityName"

5. 1-N Relationship

Consider the relationship below

With the N side entity as the base entity, here are the sample sads.js entities

Department

pk sk Name
DEPARTMENT#8260eb3a-b4d4-421a-9747-883c24ab57e0 DEPARTMENT HR
DEPARTMENT#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec DEPARTMENT Sales

Employees

pk sk Name DepartmentKey
EMPLOYEE#677dbc6b-909e-4537-8aa1-a7e56046d8aa EMPLOYEE John DEPARTMENT#8260eb3a-b4d4-421a-9747-883c24ab57e0
EMPLOYEE#4e81ad03-6213-47b4-a96d-3d76fc4e77ec EMPLOYEE Herry DEPARTMENT#8260eb3a-b4d4-421a-9747-883c24ab57e0
EMPLOYEE#85b8b502-bc93-42b8-b7c8-f0486ce7f41c EMPLOYEE Tom DEPARTMENT#8260eb3a-b4d4-421a-9747-883c24ab57e0
EMPLOYEE#380268b2-6f01-4d53-8948-f9c41fa2cc53 EMPLOYEE Jerry DEPARTMENT#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec
EMPLOYEE#ef9357aa-7952-4dcc-b500-ba6f2600bd42 EMPLOYEE Mike DEPARTMENT#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec

6. N-M Relationship

Consider the relationship below

  • Set Order as the base entity. Then you don't have to do anything with Order
  • Set Item.sk as OrderId. Saying, Item.sk = Order.pk

Here are the sample records:

Orders

pk sk Name
ORDER#8260eb3a-b4d4-421a-9747-883c24ab57e0 ORDER Bunnings
ORDER#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec ORDER Coles Pty Ltd

Items

pk sk Name
ITEM#677dbc6b-909e-4537-8aa1-a7e56046d8aa ORDER#8260eb3a-b4d4-421a-9747-883c24ab57e0 Spanner
ITEM#4e81ad03-6213-47b4-a96d-3d76fc4e77ec ORDER#8260eb3a-b4d4-421a-9747-883c24ab57e0 Hammer
ITEM#85b8b502-bc93-42b8-b7c8-f0486ce7f41c ORDER#8260eb3a-b4d4-421a-9747-883c24ab57e0 Nails
ITEM#380268b2-6f01-4d53-8948-f9c41fa2cc53 ORDER#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec Milk
ITEM#ef9357aa-7952-4dcc-b500-ba6f2600bd42 ORDER#db5873aa-2b8e-4b79-aec5-4afd21e4d7ec White Bread

Stay in touch

sads.js's People

Contributors

derekji avatar

Watchers

James Cloos avatar  avatar

sads.js's Issues

DELETE Request

Allow users to DELETE records.

By default, it should be soft-delete by setting enable as false.

An extra parameter should be supported for hard delete.

REJECT_FIELDS or IGNORE_FIELDS for create/update

Currently, any fields included in the request json body will be saved into database.

Assume USER has a field 'department' which is an object of the department, but designed as departmentId linking to the department record. In this case, GET requests contain 'department' as a property. But if it is included in the request body (POST/PUT/PATCH), USER record will contain the nested object. Appearantly that is not what we expect.

To avoid that, a list could be set up for ignorance.

ALLOWED_RESOURCES

The current AppController accepts any string as a resource.

In real projects, it should not be the case. However, it's so stupid to create lots of controllers which are exactly same except the name.

A list for allowed resources could be used to reject any requests to unallowed resources.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.