{"id":19798227,"url":"https://github.com/galib-23/prisma-postgres","last_synced_at":"2025-09-04T02:34:09.646Z","repository":{"id":243324240,"uuid":"811893351","full_name":"Galib-23/Prisma-Postgres","owner":"Galib-23","description":"This is a boilerplate code for backend with prisma and Postgresql","archived":false,"fork":false,"pushed_at":"2024-06-08T04:55:36.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T16:39:24.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Galib-23.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-07T14:17:06.000Z","updated_at":"2024-06-08T04:55:39.000Z","dependencies_parsed_at":"2024-11-12T07:30:49.911Z","dependency_job_id":null,"html_url":"https://github.com/Galib-23/Prisma-Postgres","commit_stats":null,"previous_names":["galib-23/prisma-postgres"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Galib-23/Prisma-Postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galib-23%2FPrisma-Postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galib-23%2FPrisma-Postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galib-23%2FPrisma-Postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galib-23%2FPrisma-Postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Galib-23","download_url":"https://codeload.github.com/Galib-23/Prisma-Postgres/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Galib-23%2FPrisma-Postgres/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273542176,"owners_count":25124109,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T07:28:33.852Z","updated_at":"2025-09-04T02:34:09.610Z","avatar_url":"https://github.com/Galib-23.png","language":"TypeScript","readme":"# Calibrating Prisma with Postgres on node.js\n\u003cbr\u003e\n\n**1.** First run this command to initiate the **package.json** file\n```bash\nnpm init -y\n```\n\n**2.** Install the following dependencies:\n\n```bash\nnpm i --save-dev prisma typescript ts-node @types/node nodemon\n```\n\n**3.** Now configure the **tsconfig.json** file as like this:\n```javascript\n{\n    {\n    \"compilerOptions\": {\n        \"sourceMap\": true,\n        \"outDir\": \"dist\",\n        \"strict\": true,\n        \"lib\": [\"ESNext\"],\n        \"esModuleInterop\": true\n        }\n    }\n}\n```\n\n**4.** Initialize prisma along with the database using the following command:\n```bash\nnpx prisma init --datasource-provider postgresql\n``` \n\n**5.** Now we can see that a boilerplate **schema.prisma** file along with a **.env** file is created.\n\n**6.** Setup a local postgres database and put the connection url in **.env** file.\n\n**7.** Create the models. e.g:\n```prisma\nmodel User {\n  id   Int    @id @default(autoincrement())\n  name String\n}\n```\n**8.** Add the created model to make changes in the database.\n```bash\nnpx prisma migrate dev --name init\n```\n*it would create a new migration file to interact with the database.*\n\n**9.** Install the prisma client library:\n```bash\nnpm i @prisma/client\n```\n\n**10.** *Manually regenarate prisma client:*\n```bash\nnpx prisma generate\n```\n\n**11.** It would give some pieces of code as follows:\n```javascript\nimport { PrismaClient } from '@prisma/client'\nconst prisma = new PrismaClient()\n```\n\n**12.** Create a file **script.ts** and paste that code.\n\n***#** Boilerplate for **script.ts** :*\n```typescript\nimport { PrismaClient } from \"@prisma/client\";\nconst prisma = new PrismaClient();\n\nasync function main() {\n  // ....  Prisma client queries here\n  const user = await prisma.user.create({\n    data: {\n        name: \"Galib\"\n    }\n  });\n  console.log(user);\n}\n\nmain()\n  .catch((e) =\u003e {\n    console.log(e.message);\n  })\n  .finally(async () =\u003e {\n    await prisma.$disconnect();\n  });\n```\n\n**13.** Playing with models:\n```prisma\nmodel User {\n  //field level attributes\n  id             String          @id @default(uuid())\n  name           String\n  email          String          @unique\n  age            Int\n  role           Role            @default(BASIC)\n  writtenPosts   Post[]          @relation(\"WrittenPosts\")\n  favoritedPosts Post[]          @relation(\"FavoritePosts\")\n  userPreference UserPreference?\n\n  //block level attributes\n  @@unique([age, name])\n  @@index([email])\n}\n\nmodel UserPreference {\n  id           String  @id @default(uuid())\n  emailUpdates Boolean\n  user         User    @relation(fields: [userId], references: [id])\n  userId       String  @unique\n}\n\nmodel Post {\n  id            String     @id @default(uuid())\n  title         String\n  averageRating Float\n  createdAt     DateTime   @default(now())\n  updatedAt     DateTime   @updatedAt\n  author        User       @relation(\"WrittenPosts\", fields: [authorId], references: [id])\n  authorId      String\n  favoritedBy   User?      @relation(\"FavoritePosts\", fields: [favoritedById], references: [id])\n  favoritedById String?\n  categoryId    String?\n  categories    Category[]\n\n  //@@id([title, authorId])\n}\n\nmodel Category {\n  id    String @id @default(uuid())\n  name  String @unique\n  posts Post[]\n}\n\nenum Role {\n  BASIC\n  ADMIN\n}\n```\n\n**14.** After creating the model/Schema, Migrate to database:\n```bash\nnpx prisma migrate dev\n```\n\n**15.** Regenerate Prisma client\n```bash\nnpx prisma generate\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalib-23%2Fprisma-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalib-23%2Fprisma-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalib-23%2Fprisma-postgres/lists"}