Coder Social home page Coder Social logo

fastify-prisma's Introduction

Fastify + Prisma

  • A basic setup of a Fastify app using Prisma to interact with Postgres.

Setup

  • Rename .env.example to .env and replace the placeholder values in DATABASE_URL with the actual values of your database instance.

Commands

  • yarn dev

Runs the app in dev mode by default on http://localhost:4000.

Todo

  • Add migrations
  • Refactor error handling
  • Validate request body (zod)
  • Add better logging in development

fastify-prisma's People

Contributors

jolg42 avatar renovate-bot avatar ryands17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fastify-prisma's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency typescript to v4.9.5
  • Update dependency unique-names-generator to v4.7.1
  • Update postgres Docker tag to v12.18
  • Update prisma to v3.15.2 (@prisma/client, prisma)
  • Update test-utils (@types/jest, @types/supertest, jest, jest-environment-node, supertest, ts-jest)
  • Update actions/cache action to v4
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update dependency dotenv-cli to v7
  • Update dependency fastify to v4
  • Update dependency fastify-helmet to v7
  • Update dependency husky to v9
  • Update dependency jsonwebtoken to v9
  • Update dependency lint-staged to v15
  • Update dependency nodemon to v3
  • Update dependency prettier to v3
  • Update dependency typescript to v5
  • Update postgres Docker tag to v16
  • Update prisma to v5 (major) (@prisma/client, prisma)
  • Update test-utils (major) (@types/jest, @types/supertest, jest, jest-environment-node, ts-jest)
  • Update ts-types (major) (@types/jsonwebtoken, @types/node, @types/prettier)
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/main.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/cache v2
  • postgres 12.5-alpine
npm
package.json
  • @prisma/client 3.1.1
  • bcrypt 5.0.1
  • fastify 3.22.0
  • fastify-cors 6.0.2
  • fastify-helmet 5.3.2
  • jsonwebtoken 8.5.1
  • @types/bcrypt 10.0.28-alpha
  • @types/jest 27.0.2
  • @types/jsonwebtoken 8.5.5
  • @types/node 16.10.2
  • @types/nodemon 1.19.1
  • @types/prettier 2.4.1
  • @types/supertest 2.0.11
  • dotenv-cli 4.0.0
  • husky 7.0.2
  • jest 27.2.4
  • jest-environment-node 27.2.4
  • lint-staged 11.2.0
  • nodemon 2.0.13
  • prettier 2.4.1
  • prisma 3.1.1
  • supertest 6.1.6
  • ts-eager 2.0.2
  • ts-jest 27.0.5
  • ts-node 10.2.1
  • typescript 4.4.3
  • typesync 0.8.0
  • unique-names-generator 4.6.0

  • Check this box to trigger a request for Renovate to run again on this repository

Use Types in Request Body of the Route Hander

Hello Ryan,
Thanks so much for this skeleton. I am using it in my project. I have just one question. I am trying to pass certain variables in my Request Body. In your implementation, you had this like request.body as any. I read through the Fastify documentation and I zeroed down to something like:

    type AuthLoginBodyRequest = FastifyRequest<{
      Body: {
        phone_number: string,
        password: string
      };
    }>

    export const login: RouteHandlerMethod = async (request: AuthLoginBodyRequest , reply) => {
      const { phone_number, password } = request.body;

      // Login code which eventually returns a user object

      return reply.send({ user });
    };

However, this is not working for me. I get the error below:

TSError: โจฏ Unable to compile TypeScript:
src/controllers/auth.ts:14:14 - error TS2322: Type '(this: FastifyInstance<...>, request: AuthLoginBodyRequest, reply: 
  FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>) => Promise<...>' is not assignable to type 'RouteHandlerMethod<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>'.
    Types of parameters 'request' and 'request' are incompatible.
      Type 'FastifyRequest<RouteGenericInterface, Server, IncomingMessage>' is not assignable to type 'AuthLoginBodyRequest'.
        Type 'RouteGenericInterface' is not assignable to type '{ Body: { phone_number: string; password: string; }; }'.
          Types of property 'Body' are incompatible.
            Type 'unknown' is not assignable to type '{ phone_number: string; password: string; }'.

Any ideas as to why this could be happening? I will be very grateful!
14 export const login: RouteHandlerMethod = async (request: AuthLoginBodyRequest, reply) => {

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.