Fullstack track: The Database

Learn how to provision and interact with a backend data from code in a jiffy using Prisma + graphql!

Latest Post Prescriptive Power: Unleash the Efficiency of Specificity! by Matthew Davis public

Learn how to provision and interact with a backend data from code in a jiffy using Prisma + graphql!

Prisma is an open-source ORM for Node.js and TypeScript. It is used as an alternative to writing plain SQL, or using another database access tool such as SQL query builders (like knex.js) or ORMs (like TypeORM and Sequelize). Prisma currently supports PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and CockroachDB (Preview).

What is a database?

A database is a tool used by developers to store and manage data for their applications. Think of it as a large electronic filing cabinet where you can store information and retrieve it quickly and easily. Databases are an essential component of many modern applications, from simple websites to complex enterprise systems.

There are many different types of databases, but they all share some common features. At its core, a database consists of one or more tables that store information in a structured way. Each table contains rows and columns, with each row representing a single record and each column representing a specific piece of information about that record.

Databases are used to store and manage all types of data, such as customer information, financial transactions, and inventory records. They are also used to track user activity, store log files, and manage security credentials.

In addition to storing data, databases can also perform a wide range of operations on that data, such as searching, sorting, filtering, and aggregating. This makes it easy for developers to extract the information they need from the database and use it in their applications.

Overall, databases are an essential tool for developers who need to store and manage large amounts of data in a structured and efficient way. They help developers build more powerful, flexible, and scalable applications that can handle a wide range of use cases and data types. If you are new to development, it's important to understand how databases work and how to use them effectively to build robust and reliable applications.

Anatomy of the database

Setup the backend side

#           ____      ____     __             __
#          / __/_  __/ / /____/ /_____ ______/ /__
#         / /_/ / / / / / ___/ __/ __ `/ ___/ //_/
#       / __/ /_/ / / (__  ) /_/ /_/ / /__/ ,< ____
#      /_/  \__,_/_/_/____/\__/\__, _/\___/_/|_/ / /__  ____ ____
#                                  / ___/ __ \/ / / _ \/ __ `/ _ \
#        we learn & earn πŸš€      / /__/ /_/ / / /  __/ /_/ /  __/
#   \___/\____/_/_/\___/\__, /\___/
#                                                   /____/
version: "3"

    image: postgres:latest
      - "5432:5432"
    image: dpage/pgadmin4
    container_name: fullstack-pgadmin
      - "5050:80"



Start the services

docker-compose up -d
shell command

To view the output and logs of the services run:

docker-compose logs -f
shell command

To stop viewing the logs press CTRL + C on windows or CMD + C on mac.


Name Value
Admin web UI http://localhost:5050
Connection string postgres://
Hostname localhost
Port 5432

See also

GitHub - fullstackcollege/example-docker-postgres
Contribute to fullstackcollege/example-docker-postgres development by creating an account on GitHub.
Find the full example in this GitHub repository.

Setup the application side


npm install prisma --save-dev
npm install @prisma/client
shell command


Initialize a prisma.schema file:

npx prisma init
shell command


Tell prisma what database to use and connect to:

datasource db {
  provider = "postgres"
  url      = env("DATABASE_URL")

generator client {
  provider = "prisma-client-js"

Define your first tables

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

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

Update the database

prisma migrate dev --name init
shell command

Putting it all together


Matthew Davis

Published a year ago