xonecas.io
4515
Nr

node-react-typescript-boilerplate / commit fb0e56b

Adds prisma and a default User table

Sean2023-01-10 fb0e56bd2fdf1e8e3ad3902010226ba4be3e3429 parent 01ff0c7

8 files changed

package-lock.json+49−0
@@ -5,12 +5,14 @@
55 "packages": {
66 "": {
77 "dependencies": {
8+ "@prisma/client": "^4.8.1",
89 "@types/koa-static": "^4.0.2",
910 "koa": "^2.14.1",
1011 "koa-json": "^2.0.2",
1112 "koa-logger": "^3.2.1",
1213 "koa-router": "^12.0.0",
1314 "koa-static": "^5.0.0",
15+ "prisma": "^4.8.1",
1416 "strip-ansi": "6.0.0"
1517 },
1618 "devDependencies": {
@@ -24,6 +26,37 @@
2426 "typescript": "^4.9.4"
2527 }
2628 },
29+ "node_modules/@prisma/client": {
30+ "version": "4.8.1",
31+ "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.8.1.tgz",
32+ "integrity": "sha512-d4xhZhETmeXK/yZ7K0KcVOzEfI5YKGGEr4F5SBV04/MU4ncN/HcE28sy3e4Yt8UFW0ZuImKFQJE+9rWt9WbGSQ==",
33+ "hasInstallScript": true,
34+ "dependencies": {
35+ "@prisma/engines-version": "4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe"
36+ },
37+ "engines": {
38+ "node": ">=14.17"
39+ },
40+ "peerDependencies": {
41+ "prisma": "*"
42+ },
43+ "peerDependenciesMeta": {
44+ "prisma": {
45+ "optional": true
46+ }
47+ }
48+ },
49+ "node_modules/@prisma/engines": {
50+ "version": "4.8.1",
51+ "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.8.1.tgz",
52+ "integrity": "sha512-93tctjNXcIS+i/e552IO6tqw17sX8liivv8WX9lDMCpEEe3ci+nT9F+1oHtAafqruXLepKF80i/D20Mm+ESlOw==",
53+ "hasInstallScript": true
54+ },
55+ "node_modules/@prisma/engines-version": {
56+ "version": "4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe",
57+ "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe.tgz",
58+ "integrity": "sha512-MHSOSexomRMom8QN4t7bu87wPPD+pa+hW9+71JnVcF3DqyyO/ycCLhRL1we3EojRpZxKvuyGho2REQsMCvxcJw=="
59+ },
2760 "node_modules/@types/accepts": {
2861 "version": "1.3.5",
2962 "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.5.tgz",
@@ -1017,6 +1050,22 @@
10171050 "url": "https://github.com/sponsors/jonschlinkert"
10181051 }
10191052 },
1053+ "node_modules/prisma": {
1054+ "version": "4.8.1",
1055+ "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.8.1.tgz",
1056+ "integrity": "sha512-ZMLnSjwulIeYfaU1O6/LF6PEJzxN5par5weykxMykS9Z6ara/j76JH3Yo2AH3bgJbPN4Z6NeCK9s5fDkzf33cg==",
1057+ "hasInstallScript": true,
1058+ "dependencies": {
1059+ "@prisma/engines": "4.8.1"
1060+ },
1061+ "bin": {
1062+ "prisma": "build/index.js",
1063+ "prisma2": "build/index.js"
1064+ },
1065+ "engines": {
1066+ "node": ">=14.17"
1067+ }
1068+ },
10201069 "node_modules/process-nextick-args": {
10211070 "version": "2.0.1",
10221071 "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
package.json+2−0
@@ -10,12 +10,14 @@
1010 "typescript": "^4.9.4"
1111 },
1212 "dependencies": {
13+ "@prisma/client": "^4.8.1",
1314 "@types/koa-static": "^4.0.2",
1415 "koa": "^2.14.1",
1516 "koa-json": "^2.0.2",
1617 "koa-logger": "^3.2.1",
1718 "koa-router": "^12.0.0",
1819 "koa-static": "^5.0.0",
20+ "prisma": "^4.8.1",
1921 "strip-ansi": "6.0.0"
2022 }
2123 }
prisma/dev.db+0−0
Binary file, not shown.
prisma/dev.db-journal+0−0
Binary file, not shown.
prisma/migrations/20230110120950_init/migration.sql+10−0
@@ -0,0 +1,10 @@
1+-- CreateTable
2+CREATE TABLE "User" (
3+ "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
4+ "email" TEXT NOT NULL,
5+ "name" TEXT,
6+ "password" TEXT NOT NULL
7+);
8+
9+-- CreateIndex
10+CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
prisma/migrations/migration_lock.toml+3−0
@@ -0,0 +1,3 @@
1+# Please do not edit this file manually
2+# It should be added in your version-control system (i.e. Git)
3+provider = "sqlite"
prisma/schema.prisma+18−0
@@ -0,0 +1,18 @@
1+// This is your Prisma schema file,
2+// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+generator client {
5+ provider = "prisma-client-js"
6+}
7+
8+datasource db {
9+ provider = "sqlite"
10+ url = env("DATABASE_URL")
11+}
12+
13+model User {
14+ id Int @id @default(autoincrement())
15+ email String @unique
16+ name String?
17+ password String
18+}
src/index.ts+43−28
@@ -1,39 +1,54 @@
1+import { PrismaClient } from "@prisma/client";
12 import Koa from "koa";
2-import Router from "koa-router";
33 import json from "koa-json";
44 import logger from "koa-logger";
5+import Router from "koa-router";
56 import serve from "koa-static";
67 import stripAnsi from "strip-ansi";
78
89 // try got and axios for server to server requests
910
10-const app = new Koa();
11-const router = new Router();
12-
13-// health-check:
14-router.get("/health-check", async (ctx, next) => {
15- ctx.body = {
16- data: "Hello World!",
17- };
18- await next();
19-});
20-
21-// Middleware:
22-app.use(
23- logger((str) => {
24- // Remove colors since they clash with my terminal
25- console.log(stripAnsi(str));
26- })
27-);
28-app.use(json());
11+const prisma = new PrismaClient();
12+
13+async function main() {
14+ const app = new Koa();
15+ const router = new Router();
2916
30-// Serve build react app
31-app.use(serve("client/build"));
17+ // health-check:
18+ router.get("/health-check", async (ctx, next) => {
19+ ctx.body = {
20+ data: "Hello World!",
21+ };
22+ await next();
23+ });
3224
33-// Serve configured routes:
34-app.use(router.routes()).use(router.allowedMethods());
25+ // Middleware:
26+ app.use(
27+ logger((str) => {
28+ // Remove colors since they clash with my terminal
29+ console.log(stripAnsi(str));
30+ })
31+ );
32+ app.use(json());
3533
36-// App starts
37-app.listen(3001, () => {
38- console.log("Server started...");
39-});
34+ // Serve build react app
35+ app.use(serve("client/build"));
36+
37+ // Serve configured routes:
38+ app.use(router.routes()).use(router.allowedMethods());
39+
40+ // App starts
41+ app.listen(3001, () => {
42+ console.log("Server started...");
43+ });
44+}
45+
46+main()
47+ .then(async () => {
48+ await prisma.$disconnect();
49+ })
50+ .catch(async (e) => {
51+ console.error(e)
52+ await prisma.$disconnect();
53+ process.exit()
54+ });