![]() Let create our DB and name it reflection_db. Run the following command to install the two packages $ npm install -save pg dotenv ![]() Lastly, we need to install PG and dotenv(we need this to load our environment variables from. Your new project structure should look like the following project Create Reflection.js js file in controller folder and index.js in db folder. Next, create two new folders inside usingDB - controllers and db. Move the previous folders in src to usingJSObject folder. Create two new folders in src - usingJSObject and usingDB. Now, let's make some tweak to our project structure. To check if progress was installed successfully, run which psql from the terminal Using PG alone will also give us the opportunity to understand some basic SQL queries as we will be querying and manipulating data in the DB using raw SQL queries. Instead of using an ORM, we will use PG NodeJS package directly - PG is a NodeJs package for interfacing with the PostgreSQL database. We have several ORM packages that could be used with our database e.g Sequelize. ORM packages expose some methods needed to query and manipulate the data in the database. ORM is basically a technique that allows us to query and manipulate data from the database with little or zero knowledge of SQL. Check out this answer on stackoverflow to get a better understanding of ORM. To make this simple and so that we can have a better understanding of how SQL works, I'm not going to make use ORM(Object Relational Mapping) in this post. SQL is basically the only language you can use in querying data in the database. ![]() SQL is a standard language for storing, manipulating and retrieving data in databases. We will also learn how to write some basic (Structure Query Language) queries. In this post, I'll explain how to connect and use PostgreSQL Database to store input data as opposed to JavaScript Object datatype we used in part 1. Click here to read my post on Building a simple API with Nodejs, Expressjs, and JS Data structure to persist data. If you have not read my previous post, please do. This tutorial is a continuation from where we stopped from the last post. "There is always one more bug to fix." Ellen Ullman ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |