Giter Club home page Giter Club logo

boilerplate-express-prisma's Introduction

Boilerplate Express Prisma

Simple Boilerplate Express.js, Prisma ORM, Docker Compose, PostgreSQL Database

Table of Contents

Running on Localhost

  • Clone this repository
git clone https://github.com/armandwipangestu/boilerplate-express-prisma && cd boilerplate-express-prisma
  • Running Docker Compose

Note: This command will install the docker compose service such as db (PostgreSQL) and adminer

Here are some information

Service Port Mapping Database User Password
db 5432:5432 testDB postgres postgres
adminer 8080:8080 - - -
docker compose up
  • Install dependency
yarn
  • Copy .env.example to .env file
cp .env.example .env
  • Change DATABASE_URL value with your database own database configuration, for example
DATABASE_URL="postgresql://username:password@localhost:5432/database_name?schema=public"
  • Migrate the database
npx prisma migrate dev
  • Seeding the tables
npx prisma db seed
  • Running the app
npm run dev

Data Models

Data Models

In this boilerplate, i'm just create a data model like above, here the detail about the relationship

Table A Table B Relationship Description
user profile One-to-One -
user post One-to-Many -
post category Many-to-Many This explicit many-to-many relationship need intermediate model/tabel, so i'm use _CategorysOnPost as the intermediate
post _CategorysOnPost One-to-Many -
category _CategorysOnPost One-to-Many -

Prisma Cheatsheet

  • Initialize

Run this command if you first setup with the prisma, prisma will generate the .env file and generate prisma/schema.prisma file for the data model

npx prisma init
  • Introspection

Run this command if you have already database and inside the database already defined the tables, so prisma introspection will create the data model based on the tables inside your database. So the database will be the single source of tools.

npx prisma db pull
  • Migration

Run this command if you don't have a database, but with this migration you must have a data model first by creating manually then you run the migration and your tables inside your database will be created based on data models in the prisma/schema.prisma file

Note: Mostly if you run the migration first time, the migration name use init

npx prisma migrate dev --name <migration_name>
  • Prisma Studio

Run this command if you want to open a model via web

npx prisma studio
  • Seeding

Note: Make sure you check the package.json file that have the custom command like this

"prisma": {
   "seed": "node prisma/seed.js"
},
npx prisma db seed

Bundling and Running the Docker Container

  • Build the app into container
docker build -t boilerplate-express-prisma .
  • Running the container
docker run -it -p 5000:5000 boilerplate-express-prisma
  • Running with Compose

Note: Add this boilerplate-express-prisma service into docker-compose.yaml file

version: "3"
services:
    db: ...

    adminer: ...

    boilerplate-express-prisma:
        build:
            context: .
        environment:
            DATABASE_URL: "postgresql://postgres:postgres@localhost:5432/testDB?schema=public"
            API_VERSION: "/api/v1"
        depends_on:
            - db
        ports:
            - "5000:5000"

boilerplate-express-prisma's People

Contributors

armandwipangestu avatar

Stargazers

 avatar

Watchers

 avatar

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.