Git Product home page Git Product logo

thisdot-prisma's Introduction

Type-Safe Databases with Prisma

๐Ÿ‘‹ Welcome to the repository for Type-Safe Databases with Prisma!

This repo contains an express API that uses Prisma for database access. It is the resource that we'll use in my hour-long session on Prisma for This Dot Labs.

Download and Install

Clone the repository and install dependencies:

npm install

Run the Migrations

There is a file called schema.prisma found in the prisma directory. This is the definition for the database model. To create the tables for the database, we need to run migrations.

Start by saving a new migration.

npx prisma migrate save --experimental

Then run the migartion to create the tables.

npx prisma migrate up --experimental

Then generate the Prisma types for the data model.

npx prisma generate

Run the App

The API is built using express with TypeScript and uses ts-node-dev for development. There is a script in package.json that runs the app in development mode.

npm run dev

The Database

This repo uses SQLite, a file-system database that is great for development and proof-of-concept work but is not well-suited to production. The data that we create and read here is found in the file called dev.db in the prisma directory. You are free to use a different database such as MySQL or Postgres if you like. To do so, adjust the datasource configuration in the schema.prisma file.

Access the Routes

Have a look in server.ts. This file contains all the express endpoints for data access and creation. As an example, go to http://localhost:3001/products in your browser to view a list of all the products in the database.

This list will initially be empty and you'll need to create some products to get started with. You can do that with the POST endpoint for products.

Send a POST request to http://localhost:3001/products with the following payload:

{
  "name": "My first product",
  "description": "A great product",
  "price": 5000,
  "sku": "111"
}

License

MIT

thisdot-prisma's People

Contributors

chenkie avatar

Stargazers

Odhiambo Dormnic avatar paulwvnjohi avatar Antonio Mata avatar

Watchers

James Cloos avatar  avatar  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.