Create PostgreSQL database & user
In the preceding guides, we covered the basics of implementing a backend application using Node.js and GraphQL. In addition, we detailed the steps necessary to set up Express.js with TypeScript and GraphQL. Mocking allowed us to get Apollo Server up and running as a GraphQL server before implementing the resolvers that are meant to perform the actual work of retrieving and inserting data.
This guide will cover the basics of using TypeORM to connect to a relational database and retrieve and store data in your application.
Now that our GraphQL-based backend application is complete, we must link it to our data store. We'll use TypeORM to abstract the database operations, making it possible to switch to a different DBMS without modifying the code. We'll also cover database table creation and seeding, as well as integrating TypeORM with Apollo.
First you need to create a user and database in your database. In PostgreSQL, you can use the following commands.
First log in PostgreSQL using the following command:
su - postgres
Next, run:
CREATE USER dbuser WITH PASSWORD '12345689';
Next, give the necessary permissions using the following command:
GRANT ALL PRIVILEGES ON * . * TO dbuser@'localhost';
Next, create the database as follows:
FLUSH PRIVILEGES;
create database communitydb;
So long! We have a user named dbuser who logs in with the password 123456789 and a database called communitydb. In the next part, we'll use these credentials to set up TypeORM.
-
Date: