Reputation: 430
I know the title is silly but I'm in real confusion now. Let's me explain the details:
I'm going to build a new webapp using NextJS (basically React) and I want my backend to use GraphQL. When searching for some additional technologies, I found Prisma
but don't understand it correctly even reading the whole docs & website.
Nextjs
in FE, Nodejs
to build GraphQL APIs
in BE, using MongoDB
or PostgresQL
as DBPrisma
. When searching for some expamles, I have something growing in my mind:Prisma
is like a version of LinQ in Nodejs app?NextJS
(FE) can use Prisma
to query data from DB → Where is the BE part? Is Prisma considered BE?React Native
+ Prisma
, correct?Prisma
in Nodejs app (BE) to build APIs. Why do we need Prisma
when Nodejs
+ MongoDB
is enough?I'm so confused about them so I hope the questions are clear.
Upvotes: 3
Views: 7213
Reputation: 1
I do not believe Mongoose is an ORM, it's an ODM. MongoDB is intrinsically non-relational, it's a Document Database. I suppose including Mongoose isn't that criminal in the list of ORM's, but really I think the differentiation is still important.
Upvotes: -2
Reputation: 1608
ORM is an object-relational mapper. Meaning you don't have to write certain Database queries from scratch
Example raw mongodb query
db.mycol.findOne({title: "MongoDB Overview"})
{
"_id" : ObjectId("5dd6542170fb13eec3963bf0"),
"title" : "MongoDB Overview",
"description" : "MongoDB is no SQL database",
"by" : "tutorials point",
"url" : "http://www.tutorialspoint.com",
"tags" : [
"mongodb",
"database",
"NoSQL"
],
"likes" : 100
}
using an ORM like Mongoosejs or Prisma
Mongoosejs
let character = await Character.findOne({ name: 'Frodo' })
Prisma
const allPosts: Post[] = await prisma.post.findMany()
ORM makes your life easier. If you like to write raw queries, go ahead :)
List of ORMs that you can choose from
For me, I would personally go with Prisma or Mongoose
Upvotes: 6
Reputation: 7618
Prisma is a Database Toolkit so that's definitely a part of the Backend.
The Database Toolkit involves Prisma ORM (Basically you won't have to write RAW SQL Queries in your GraphQL API to fetch data from your database, Prisma will do it for you). You will write your Prisma Queries in your GraphQL queries to fetch data and mutations to create data.
Next.js blurs the lines between client and server. You can use Prisma in the front end with Next.js in getStaticProps()
, getServerSideProps()
and API Routes
but in your case, this won't be scalable as the mobile app cannot use these methods. Instead, a stand-alone server will be preferable and your GraphQL APIs can be consumed by both the Next.js Web App as well as React Native mobile app.
By using Prisma along with Node.js and MongoDB would make building app faster as Prisma exposes CRUD and other aggregation operations using PrismaClient based on your models.
This official example of using Prisma with GraphQL and Next.js should be helpful.
Upvotes: 2