david32145 / nodejs-reflect-metadata

An app using the reflect-metada api.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NodeJS Reflect Metada

This app is like the features of an common ORM, but only the findAll and create methods. The app uses decorations in the declarations of models .

πŸ‘¨πŸΌβ€πŸ’» Development Contact

David Nascimento

πŸš€ Technologies

  • ts-node-dev;
  • dotenv;
  • typescript;
  • reflect-metadat;
  • knex;
  • mysql;

🎌 What I've learned

  • The reflect api;
  • Environment vars;
  • Typescript decorations;
  • How doing an ORM πŸ˜….

πŸŽ₯ How Usage

With decoration you can declarate the model like this:

@Table("users")
class User extends Repository{
  @Column("id", true)
  public id!: number
  @Column("name")
  public name!: string
  @Column("email")
  public email!: string
  @Column("description")
  public description!: string

  public toJSON(): Object {
    return {
      id: this.id,
      name: this.name,
      email: this.email,
      description: this.description
    }
  }
}

User
  .findAll()
  .then(console.log)

You can be view the full example into src/index.ts .

βœ‹πŸ» Prerequisites

πŸ”₯ Install and Running

  1. Config you environment;
  2. Git clone git clone https://github.com/david32145/nodejs-reflect-metadata ;
  3. Run yarn install or npm install for install dependencies;
  4. Copy .env.example to .env and fill with your config. Below an example of .env ;
DB_HOST=localhost
DB_PORT=3306
DB_NAME=reflect_matadata
DB_USER=root
DB_PASS=root
  1. Run yarn migration:up or npm run migration:up for up database migrations;
  2. Run yarn dev or npm run dev
  3. Edit src/index.ts and start the game.

About

An app using the reflect-metada api.


Languages

Language:TypeScript 100.0%