mkdir test-fastify && cd test-fastify
pnpm init -y
pnpm i fastify
pnpm i -D typescript @types/node
pnpm exec tsc --init
tsconfig.json
{
"compileOptions": {
"target": "ES2021",
"module": "ES2022",
"moduleResolution": "node"
}
}
package.json
{
"scripts": {
"build": "tsc -p tsconfig.json",
"start": "node index.js"
}
"type": "module",
}
pnpm i prisma
pnpm exec prisma init --datasource-provider sqlite
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Fighter {
id Int @id @default(autoincrement())
name String @unique
skill String
created_at DateTime @default(now())
updated_at DateTime?
@@map("fighter")
}
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="file:./fighter.db"
pnpm exec prisma migrate dev --name init-fighter-schema
pnpm exec prisma generate
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
pnpm i @sinclair/typebox @fastify/type-provider-typebox
pnpm i @fastify/cors
pnpm i @fastify/swagger
pnpm i @fastify/swagger-ui
pnpm build && pnpm start