kandi background
Explore Kits

prisma | Nextgeneration ORM | Database library

 by   prisma TypeScript Version: 3.12.0 License: Apache-2.0

 by   prisma TypeScript Version: 3.12.0 License: Apache-2.0

Download this library from

kandi X-RAY | prisma Summary

prisma is a TypeScript library typically used in Database, MongoDB, PostgresSQL, MariaDB, DynamoDB applications. prisma has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
You can ask questions and initiate discussions about Prisma-related topics in the prisma repository on GitHub. 👉 Ask a question.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • prisma has a medium active ecosystem.
  • It has 22118 star(s) with 787 fork(s). There are 204 watchers for this library.
  • There were 4 major release(s) in the last 6 months.
  • There are 2037 open issues and 4064 have been closed. On average issues are closed in 83 days. There are 55 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of prisma is 3.12.0
prisma Support
Best in #Database
Average in #Database
prisma Support
Best in #Database
Average in #Database

quality kandi Quality

  • prisma has 0 bugs and 0 code smells.
prisma Quality
Best in #Database
Average in #Database
prisma Quality
Best in #Database
Average in #Database

securitySecurity

  • prisma has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • prisma code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
prisma Security
Best in #Database
Average in #Database
prisma Security
Best in #Database
Average in #Database

license License

  • prisma is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
prisma License
Best in #Database
Average in #Database
prisma License
Best in #Database
Average in #Database

buildReuse

  • prisma releases are available to install and integrate.
  • Installation instructions, examples and code snippets are available.
prisma Reuse
Best in #Database
Average in #Database
prisma Reuse
Best in #Database
Average in #Database
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

prisma Key Features

If Prisma currently doesn't have a certain feature, be sure to check out the roadmap to see if this is already planned for the future.

The Prisma schema

copy iconCopydownload iconDownload
// Data source
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

// Generator
generator client {
  provider = "prisma-client-js"
}

// Data model
model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User?   @relation(fields:  [authorId], references: [id])
  authorId  Int?
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

Accessing your database with Prisma Client

copy iconCopydownload iconDownload
npm install @prisma/client

Reason: `object` ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types

copy iconCopydownload iconDownload
// your data
let newsLetters = [
    {
        id: 'your-id',
        email: 'email@example.com',
        createdAt: new Date()
    }
];

// map the array
newsLetters.map(x => {
    x.createdAt = Math.floor(x.createdAt / 1000);
    return x;
})

// use newsLetters now
console.log(newsLetters);
-----------------------
for (const element of newsLetters) {
  element.createdAt = element.createdAt.toString()
}

How to create a custom health check for Prisma with @nestjs/terminus?

copy iconCopydownload iconDownload
    prisma.$queryRaw`SELECT 1`
-----------------------
import { Injectable } from "@nestjs/common";
import { HealthCheckError, HealthIndicator, HealthIndicatorResult } from "@nestjs/terminus";
import { PrismaService } from "./prisma.service";

@Injectable()
export class PrismaHealthIndicator extends HealthIndicator {
  constructor(private readonly prismaService: PrismaService) {
    super();
  }

  async isHealthy(key: string): Promise<HealthIndicatorResult> {
    try {
      await this.prismaService.$queryRaw`SELECT 1`;
      return this.getStatus(key, true);
    } catch (e) {
      throw new HealthCheckError("Prisma check failed", e);
    }
  }
}

Prisma using 1-1 and 1-n relation with same model

copy iconCopydownload iconDownload
model Product {
  id         String         @id @default(uuid()) @db.VarChar(36)
  image_id   String         @unique
  // image   ProductImage   @relation(name: "main_image", fields: [image_id], references: [id])
  image      ProductImage   @relation(name: "main_image", fields: [image_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
  images     ProductImage[]
  slug       String         @unique(map: "slug") @db.VarChar(255)
  title      String         @db.VarChar(255)
  created_at DateTime       @default(now())
  updated_at DateTime       @default(now()) @updatedAt

  @@map("product")
}

model ProductImage {
  id                 String    @id @default(uuid()) @db.VarChar(36)
  src                String    @db.VarChar(255)
  created_at         DateTime  @default(now())
  updated_at         DateTime  @default(now()) @updatedAt
  product_id         String
  product            Product   @relation(fields: [product_id], references: [id])
  product_main_image Product[] @relation("main_image")

  @@map("product_image")
}

NX NestJs - Unexpected error: Error: Unable to load hasher for task &quot;api:serve&quot;

copy iconCopydownload iconDownload
"executor": "@nrwl/node:execute" -> "executor": "@nrwl/node:node"
"executor": "@nrwl/node:build" -> "executor": "@nrwl/node:webpack"

How to link many to many items in Prisma without duplicates

copy iconCopydownload iconDownload
model MenuProducts {
  menu_id Int
  menu Menu @relation(fields: [menu_id], references: [id])

  product_id Int
  product Product @relation(fields: [product_id], references: [id])


  created_at DateTime @default(now())
  updated_at DateTime @updatedAt

  @@map("menu_products")

  @@id([product_id, menu_id])

  @@unique([product_id, menu_id])
}

creating objects for 1:n relation with prisma

copy iconCopydownload iconDownload
model Fish {
    name      String      @id
    boardFish BoardFish? // removed autogenerated `[]` and made optional
}

model BoardFish {
    id       Int    @id @default(autoincrement())
    name     String
    fishType Fish   @relation(fields: [name], references: [name])
}
const fish = await prisma.boardFish.create({
  data: {
    fishType: {
      connect: { name: 'salmon' }, // or `connectOrCreate` if it doesn't exist
    },
  }
})
-----------------------
model Fish {
    name      String      @id
    boardFish BoardFish? // removed autogenerated `[]` and made optional
}

model BoardFish {
    id       Int    @id @default(autoincrement())
    name     String
    fishType Fish   @relation(fields: [name], references: [name])
}
const fish = await prisma.boardFish.create({
  data: {
    fishType: {
      connect: { name: 'salmon' }, // or `connectOrCreate` if it doesn't exist
    },
  }
})

When I run nest.js, I get a Missing &quot;driver&quot; option error

copy iconCopydownload iconDownload
@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      driver: ApolloDriver,
    }),
  ],
})

How to resolve 'getUserByAccount is not a function' in next-auth?

copy iconCopydownload iconDownload
npm uninstall next-auth @next-auth/prisma-adapter
npm install @next-auth/prisma-adapter
-----------------------
npm uninstall next-auth @next-auth/prisma-adapter
npm install @next-auth/prisma-adapter

Prisma client not marking property as null

copy iconCopydownload iconDownload
prisma-script> select id, "oauthData" from "User"
+---------+-------------+
| id      | oauthData   |
|---------+-------------|
| 124124  | null        |
| 1241241 | <null>      |
+---------+-------------+

Prisma, select row from table 1, depending on the latest foreign key in table 2

copy iconCopydownload iconDownload
    let publication = await prisma.publication.findFirst({
        where: {
            id
        },
        include: {
            publicationStatus: {
                orderBy: {
                    createdAt: 'desc'
                },
                take: 1
            }
        }
    });

    // check publication.publicationStatus[0].status and handle appropriately

Community Discussions

Trending Discussions on prisma
  • Reason: `object` (&quot;[object Date]&quot;) cannot be serialized as JSON. Please only return JSON serializable data types
  • How to sample a PostgreSQL database using Prisma?
  • I need an advise about implementing a truncate option in endpoint
  • How to create a custom health check for Prisma with @nestjs/terminus?
  • Prisma using 1-1 and 1-n relation with same model
  • NX NestJs - Unexpected error: Error: Unable to load hasher for task &quot;api:serve&quot;
  • How to link many to many items in Prisma without duplicates
  • creating objects for 1:n relation with prisma
  • When I run nest.js, I get a Missing &quot;driver&quot; option error
  • How to resolve 'getUserByAccount is not a function' in next-auth?
Trending Discussions on prisma

QUESTION

Reason: `object` (&quot;[object Date]&quot;) cannot be serialized as JSON. Please only return JSON serializable data types

Asked 2022-Mar-31 at 18:49

I am using prisma and Next.js. When I try to retrieve the content from prisma in getStaticProps it does fetch the data but I can't pass it on to the main component.

export const getStaticProps = async () => {
  const prisma = new PrismaClient();
  const newsLetters = await prisma.newsLetters.findMany();
  console.log(newsLetters);

  return {
    props: {
      newsLetters: newsLetters,
    },
  };
};

As you can see in this image it is fetching as well as printing the content.

enter image description here

But when I pass I get the following error for passing it as props

Reason: `object` ("[object Date]") cannot be serialized as JSON. Please only return JSON serializable data types.

ANSWER

Answered 2021-Dec-22 at 12:43

Looks like nextJS doesn't like serializing anything but scalar types for performance reasons. You can read more in this github issue. Best way you can handle this is that you convert your Date objects to UNIX timestamp before returning them.

// your data
let newsLetters = [
    {
        id: 'your-id',
        email: 'email@example.com',
        createdAt: new Date()
    }
];

// map the array
newsLetters.map(x => {
    x.createdAt = Math.floor(x.createdAt / 1000);
    return x;
})

// use newsLetters now
console.log(newsLetters);

Source https://stackoverflow.com/questions/70449092

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install prisma

The fastest way to get started with Prisma is by following the Quickstart (5 min).
Add Prisma to an existing project
Setup a new project with Prisma from scratch
Prisma Tests Status:
E2E Tests Status:

Support

Prisma has a large and supportive community of enthusiastic application developers. You can join us on Slack and here on GitHub.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Database Libraries with Highest Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.