parent
82875408ad
commit
5c8c3dcf9e
1
.gitignore
vendored
1
.gitignore
vendored
@ -42,3 +42,4 @@ Thumbs.db
|
|||||||
.nx/workspace-data
|
.nx/workspace-data
|
||||||
|
|
||||||
*.db
|
*.db
|
||||||
|
*.db-journal
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
-- CreateTable
|
|
||||||
CREATE TABLE "User" (
|
|
||||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
||||||
"email" TEXT NOT NULL,
|
|
||||||
"name" TEXT
|
|
||||||
);
|
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE "Post" (
|
|
||||||
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
||||||
"title" TEXT NOT NULL,
|
|
||||||
"content" TEXT,
|
|
||||||
"published" BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
"authorId" INTEGER NOT NULL,
|
|
||||||
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
# Please do not edit this file manually
|
|
||||||
# It should be added in your version-control system (e.g., Git)
|
|
||||||
provider = "sqlite"
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
// 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 User {
|
|
||||||
id Int @id @default(autoincrement())
|
|
||||||
email String @unique
|
|
||||||
name String?
|
|
||||||
posts Post[]
|
|
||||||
}
|
|
||||||
|
|
||||||
model Post {
|
|
||||||
id Int @id @default(autoincrement())
|
|
||||||
title String
|
|
||||||
content String?
|
|
||||||
published Boolean @default(false)
|
|
||||||
author User @relation(fields: [authorId], references: [id])
|
|
||||||
authorId Int
|
|
||||||
}
|
|
||||||
@ -58,6 +58,22 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"passWithNoTests": true
|
"passWithNoTests": true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"prisma-generate": {
|
||||||
|
"executor": "nx:run-commands",
|
||||||
|
"defaultConfiguration": "development",
|
||||||
|
"options": {
|
||||||
|
"cwd": "apps/blakus-api",
|
||||||
|
"commands": ["npx prisma generate"]
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"development": {
|
||||||
|
"envFile": "apps/blakus-api/.env.development"
|
||||||
|
},
|
||||||
|
"production": {
|
||||||
|
"envFile": "apps/blakus-api/.env.production"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
|
|
||||||
|
|
||||||
export default async function (fastify: FastifyInstance) {
|
export default async function (fastify: FastifyInstance) {
|
||||||
fastify.get('/', async function () {
|
fastify.get('/', async function () {
|
||||||
return { message: 'Hello API' };
|
return { usersWithPosts: [] };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
// Create a user
|
|
||||||
// const user = await prisma.user.create({
|
|
||||||
// data: {
|
|
||||||
// name: 'Alice',
|
|
||||||
// email: 'alice@prisma.io',
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// console.log(user)
|
|
||||||
|
|
||||||
// View Users
|
|
||||||
// const users = await prisma.user.findMany();
|
|
||||||
// console.log(users);
|
|
||||||
|
|
||||||
// Relations
|
|
||||||
// const user = await prisma.user.create({
|
|
||||||
// data: {
|
|
||||||
// name: 'Bob',
|
|
||||||
// email: 'bob@prisma.io',
|
|
||||||
// posts: {
|
|
||||||
// create: [
|
|
||||||
// {
|
|
||||||
// title: 'Hello World',
|
|
||||||
// published: true
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// title: 'My second post',
|
|
||||||
// content: 'This is still a draft'
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// })
|
|
||||||
// console.log(user)
|
|
||||||
|
|
||||||
// Users with posts
|
|
||||||
const usersWithPosts = await prisma.user.findMany({
|
|
||||||
include: {
|
|
||||||
posts: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
console.dir(usersWithPosts, { depth: null })
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
.then(async () => {
|
|
||||||
await prisma.$disconnect();
|
|
||||||
})
|
|
||||||
.catch(async (e) => {
|
|
||||||
console.error(e);
|
|
||||||
await prisma.$disconnect();
|
|
||||||
process.exit(1);
|
|
||||||
})
|
|
||||||
5
nx.json
5
nx.json
@ -25,6 +25,11 @@
|
|||||||
"cache": true,
|
"cache": true,
|
||||||
"dependsOn": ["^build"],
|
"dependsOn": ["^build"],
|
||||||
"inputs": ["production", "^production"]
|
"inputs": ["production", "^production"]
|
||||||
|
},
|
||||||
|
"@nx/js:tsc": {
|
||||||
|
"cache": true,
|
||||||
|
"dependsOn": ["^build"],
|
||||||
|
"inputs": ["production", "^production"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|||||||
1404
package-lock.json
generated
1404
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,7 @@
|
|||||||
"@swc/core": "~1.5.7",
|
"@swc/core": "~1.5.7",
|
||||||
"@swc/helpers": "~0.5.11",
|
"@swc/helpers": "~0.5.11",
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
|
"@types/knex": "^0.15.2",
|
||||||
"@types/node": "~18.16.9",
|
"@types/node": "~18.16.9",
|
||||||
"ajv": "^8.17.1",
|
"ajv": "^8.17.1",
|
||||||
"esbuild": "^0.19.2",
|
"esbuild": "^0.19.2",
|
||||||
@ -29,7 +30,6 @@
|
|||||||
"jest-environment-node": "^29.7.0",
|
"jest-environment-node": "^29.7.0",
|
||||||
"nx": "20.4.6",
|
"nx": "20.4.6",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"prisma": "^6.4.1",
|
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"ts-node": "10.9.1",
|
"ts-node": "10.9.1",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
@ -40,10 +40,11 @@
|
|||||||
"@fastify/autoload": "~6.0.3",
|
"@fastify/autoload": "~6.0.3",
|
||||||
"@fastify/sensible": "~6.0.2",
|
"@fastify/sensible": "~6.0.2",
|
||||||
"@nativescript/core": "~8.8.0",
|
"@nativescript/core": "~8.8.0",
|
||||||
"@prisma/client": "^6.4.1",
|
|
||||||
"axios": "^1.6.0",
|
"axios": "^1.6.0",
|
||||||
"fastify": "~5.2.1",
|
"fastify": "~5.2.1",
|
||||||
"fastify-plugin": "~5.0.1"
|
"fastify-plugin": "~5.0.1",
|
||||||
|
"knex": "^3.1.0",
|
||||||
|
"sqlite3": "^5.1.7"
|
||||||
},
|
},
|
||||||
"nativescript-nx": {
|
"nativescript-nx": {
|
||||||
"prefix": "",
|
"prefix": "",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user