#Next.js and databases (Prisma, SQL...)

1 messages · Page 1 of 1 (latest)

versed scroll
#

Question about databases: what exactly is Prisma doing? Do we need it to interact with a database? Should one still learn SQL to use a relational database inside Next.js?

#

Is Prisma what Bootstrap was to CSS? Just sort of a crutch for when you don't really know CSS?

deft pewter
#

what exactly is Prisma doing?
Prisma generates database schema
Prisma lets you design database and create type-safe interface
Prisma also lets you interact with DB without writing SQL. (Though you can still use SQL)

#

Do we need it to interact with a database?
No you dont need it. However you still need a connector/driver/api to connect to a database.

#

Should one still learn SQL to use a relational database inside Next.js?
Learn concepts rather than SQL. That would be more helpful rather than the SQL itself.
Id recommend the theory on Normalization

#

Is Prisma what Bootstrap was to CSS? Just sort of a crutch for when you don't really know CSS?
Bootstrap is not just "sort of a crutch" for when you don't really know CSS... Its more like a layer of abstraction.

versed scroll
#

very helpful, @deft pewter . Which approach you'd take to learn how to interact with databases inside Next.js from scratch? I built very basic Express CRUD apps years ago when learning web dev, but since then all my professional experience has been frontend.

#

Bootstrap is not just "sort of a crutch" for when you don't really know CSS... Its more like a layer of abstraction.
I see what you mean, my take was too broad.

deft pewter
#

How to interact databases inside Next.js from scratch?

#

hmm

versed scroll
#

I wanna explore the fullstack/backend possibilities of Next.js and having issues finding any resources teaching it. Everything either is focused on the frontend or it assumes previous backend knowledge and "yada-yada" (a-la Seinfeld) the small details.

deft pewter
#

what seems to be the problem with interacting with database?

#

its pretty straightforward if you use Prisma :v

versed scroll
#

no problem per se, I just wanna learn how to do it.

#

Assuming little to no experience with databases or backend, really

deft pewter
#

then just do it :D

prisma.car.create({name:"Toyoda", wheel: 4})

late olive
#

to be honest for most things prisma syntax suffices

deft pewter
#

i really recommend it for beginners

versed scroll
#

do you recommend any teaching resource (besides the documentation) ?

late olive
#

and then you can still use rawsql function if you need to do some more complex query

deft pewter
#

i recommend using it with Typescript so you'd get autocomplete

#

and can learn as you code

versed scroll
deft pewter
#

how did you come to the conclusion that the tutorial "assumed previous backend knowledge"?

#

what kind of backend knowledge do you feel like ure missing when following the tutorial?

#

Sorry i dont have any tutorial so id figure id just help you here 😭

versed scroll
#

how did you come to the conclusion that the tutorial "assumed previous backend knowledge"?
It's just the vibe I got, tutorial spent 90% of the time explaining routing and other FE Next.js features and then for database interaction just dispatched a couple of commands with Prisma with no explanation or depth

deft pewter
#

okay so

#

Prisma is an ORM

versed scroll
#

I appreciate your help, just wanted to have some general holistic views on Prisma

deft pewter
#

do you know what an ORM is?

#

do you know what relational databases is?

versed scroll
deft pewter
#

well an ORM maps tables and stuff into object-like syntax

#

instead of writing queries to get strings of data that you need to format,
Prisma ORM converts those into ready-to-use objects

versed scroll
#

why is it an ORM used with Next.js? When I built Express backends with Mongodb or SQL there was no ORM

deft pewter
#

there was

#

you can use Prisma in Espress

#

theres also TypeORM

#

but Prisma handles more than an ORM

#

Prisma also allwos you design the schema and have it generated on the real db

#

so you dont even need to write DDL anymore

versed scroll
#

what was DDL sorry?

deft pewter
#

if you write schema like this

model Car {
  name String @id
  wheel Int
}

then your prisma.car.findOne() will always return in the form of

{
  name: string
  wheel: number
}
#

the typings are already 1:1

#

DDL = data definition language, its the creating table part of SQL

versed scroll
#

ok, starting to make sense

deft pewter
#

so you can just

const car = prisma.car.findOne(...)
return car.name 

:D

#

ORM = Object Relational Mapper

versed scroll
#

I really appreciate the time you've taken with this Alfonsus. I think I know enough what to research more about now. I'll come back if I still have doubts.

Have a great day!