⚠️ This lesson is retired and might contain outdated information.

Connect prisma to PostgreSQL database running in docker container

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

In this lesson you will learn how to connect your prisma to postgres db to be able to introspect it. We will also go trough the models and touch prisma naming convention.

Dimitri Ivashchuk: [0:00] Let's go further ahead and add the connection to our database. First, ensure that your database is running. Ours is running in Docker container so we can do docker ps to see that section is running. Now, we want to fix this string, so it connects to our database.

[0:21] Our user is postgres, the default one, and our db is prisma. We don't have the password field because we specified it in our environmental variables in the docker-compose file. Let's save this and run npx prisma introspect.

[0:53] As we see here, our database has been successfully instrospected so we can go to schema.prisma and see that it has picked up the correct model and it has picked up the correct types for the users, the only table that we have in database.

[1:10] By the way, to get this nice syntax highlighting, you can download and enable the Prisma extension in VS Code. Makes it easy to work with Prisma because everything looks better and you get to organize features like linting, autocomplete and all this fancy stuff.

[1:30] There is one important note that you might want to know when using Prisma documentation and for Prisma name and conventions. When you introspect the database with prisma introspect, you will get the names of the models in line with your database.

[1:46] If your Postgres is name to a snake case, then you will get this lowercase plural form of database tables which mean it would be users and Prisma has naming convention of capitalized first letter and singular form. In this case, it would be User.

[2:07] To map it now to our database, we would need to specify that we want to map to users. That would be it, but for the purposes of this tutorial, we will continue following the model with users and then when we will evolve our schema, we will redefine every model to follow Prisma convention.

egghead
egghead
~ 18 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today