Git Product home page Git Product logo

trpc-fastify-starter's Introduction

tRPC Starter Template with Fastify, Drizzle ORM, Jest and MySQL

This is a starter template for building a tRPC API with Drizzle ORM, MySQL, Jest and Fastify. It provides a basic structure for setting up an API with tRPC and integrating it with Drizzle ORM for database operations using MySQL, along with the Fastify framework for handling HTTP requests and Jest for testing.

Prerequisites

Before using this template, ensure that you have the following installed:

  • Node.js v18 and above
  • MySQL

Getting Started

  1. Clone the repository.
  2. Install the dependencies using pnpm i.
  3. Set up your MySQL database and configure the connection in the application.
  4. Generate the initial migration file using Drizzle's CLI.
  5. Apply the initial migration to the database.
  6. Start the server using pnpm run dev.

Project Structure

  • src/
    • db.ts - Drizzle ORM connection configuration to the MySQL database with mysql2 driver.
    • schema.ts - SQL schema.
    • router.ts - tRPC router with a procedure to use in our application.
  • migrations/ - Folder to store database migration files.

Database Migration

To create and apply database migrations, use the following commands:

  • Generate a migration: pnpm run generate-migration
  • Apply migrations: pnpm run migrate

For detailed instructions on using Drizzle ORM for migrations, refer to the Drizzle ORM documentation.

API Endpoints

The API endpoints are defined in the src/router.ts file. You can define your tRPC API handlers and schemas in this directory.

Running the Server

To start the hot reload development server, run the following command:

pnpm run dev
# try http://localhost:2000/v1/greeting
# try http://localhost:2000/v1/userById?input=1

To run tests, run the following command:

pnpm run test
# pnpm run test src/index.test.ts

trpc-fastify-starter's People

Contributors

josephgodwinkimani 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.