KEMBAR78
Module 5 Web Programing Setting Up Postgres.pptx
Setting Up Postgres
• Setting Up Postgres and a Repository Layer with TypeORM
• Technical requirements
• Setting up our Postgres database
• Understanding object relational mappers by using TypeORM
• Building our repository layer using Postgres and TypeORM
What is data
• Data can come in the form of text, observations, figures,
images, numbers, graphs, or symbols.
• For example, data might include individual prices, weights,
addresses, ages, names, temperatures, dates, or distances.
• Data is a raw form of knowledge and, on its own, doesn't
carry any significance or purpose.
What Is a Database?
• A database is an organized collection of structured
information, or data, typically stored electronically in a
computer system.
• Some real-life examples of databases include student
database, employee database, eCommerce, healthcare,
online banking systems, hotel booking systems, airline
reservation systems.
Types of Databases
• Hierarchical Databases.
• Relational Databases.
• Network Databases.
• Object oriented databases
Types of Databases
• Hierarchical Databases. data model in which the data are
organized into a tree-like structure
A relational database is a type of database that stores and provides access
to data points
• Network Databases. a database model where numerous
records or files can link to multiple owner files
object-oriented database (OOD)
• An object-oriented database (OOD) is a database system
that can work with complex data objects — that is, objects
that mirror those used in object-oriented programming
languages. In object-oriented programming (OOP),
everything is an object.
What Is a Database Management
System?
• Database Management Systems (DBMS) are software
systems used to store, retrieve, and run queries on data.
• A DBMS serves as an interface between an end-user and a
database, allowing users to create, read, update, and delete
data in the database.
• Eg. MySql, Oracle, PostgreSQL, Access, MongoDB
SQL
• What is SQL?
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
What Can SQL do?
• SQL can execute queries against a database
• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
What is PostgreSQL and why it is used?
• It is a highly stable database management system, backed
by more than 20 years of community development which
has contributed to its high levels of resilience, integrity, and
correctness.
The minimum hardware required to install and run
PostgreSQL is:
• 1 GHz processor.
• 2 GB of RAM.
• 512 MB of HDD.
Who uses PostgreSQL?
Top Companies using PostgreSQL
Company
Name
Website Revenue
Netflix
www.netflix.co
m
$24.9 Billion
Uber auth.uber.com $14.6 Billion
Instacart
www.instacart.c
om
$1.8 Billion
LaunchDarkly
launchdarkly.co
m
$57 Million
Benefits of PostgreSQL
• In other words, it offers atomicity, consistency, isolation and durability
features. PostgreSQL's advanced features include stored procedures, triggers,
user-defined functions, transactions and replication.
• PostgreSQL provides enterprise-grade scalability performance, availability and
functionality. Thus, you can deploy PostgreSQL in a distributed architecture,
which can handle large volumes of data.
• Another important feature of PostgreSQL is that it’s open source, which makes
it an affordable solution for businesses to keep costs low.
• PostgreSQL has an excellent track record of reliability and data security.
• It’s been used in production by customers for decades and is trusted by many
organizations and businesses worldwide.
How to setup the PostgreSQL?
1.Download the installer from the official PostgreSQL website:
https://www.postgresql.org/download/windows/
2.Run the installer and follow the instructions.
3.Start the PostgreSQL Service:
4.Windows: PostgreSQL service should start automatically after
installation.
5.Access PostgreSQL Shell:
6.Windows: Open the SQL Shell (psql) from the PostgreSQL folder in
the Start menu.
7.Change Password for the PostgreSQL User:
8. Windows: Open the SQL Shell (psql).
9. CREATE DATABASE your_database;
10. Switch to the New Database:
11. Create a User for the Database:
12. CREATE USER your_user WITH PASSWORD 'your_password';
13. GRANT ALL PRIVILEGES ON DATABASE your_database TO your_user;
14. Exit the PostgreSQL ShellConnect to PostgreSQL:
15. You can now connect to PostgreSQL using a database client or your
preferred programming language.For example, using the psql command-
line client:
Class
• A class is a template for creating objects in program.
• Example: Car.
Object
• The object is an instance of a class.
• Example: Jaguar, BMW, Tesla, etc.
Object Relational Mapper (ORM)
• ORM stands for Object-Relational Mapping. It is a
programming technique that allows you to interact with a
relational database using an object-oriented programming
language.
• The main purpose of an ORM is to bridge the gap between
the relational model of a database and the object-oriented
model of a programming language. With an ORM, you can
interact with the database using objects and their methods,
rather than writing raw SQL queries.
TypeScript is an open-source programming language developed by Microsoft.
TypeScript offers numerous benefits for developers
• Improved Developer Experience:
• Enhanced Code Quality:
• Large and complex web applications:
• API development:
• Reduced runtime errors:
• Improved performance:
• TypeORM is an Object-Relational Mapping (ORM) library for
TypeScript
• It enables developers to interact with relational databases
using TypeScript
• TypeORM supports a variety of database management
systems, including PostgreSQL, MySQL, MariaDB, SQLite,
and Microsoft SQL Server.
Building our repository layer using
Postgres and TypeORM
• Building a repository layer using PostgreSQL and TypeORM
involves setting up a database, defining entities, creating a
repository, and integrating TypeORM into your project.
• Below is a step-by-step guide using Node.js and TypeScript,
assuming you have Node.js and npm installed.
Step 1: Project Setup
• Create a new project and initialize it with npm:
Step 2: TypeScript Configuration
• Create a tsconfig.json file in the root directory:
Step 3: PostgreSQL Configuration
• Create a PostgreSQL database and note down the connection details
(host, username, password, database name).
Step 4: TypeORM Configuration
• Create an ormconfig.json file in the root directory:
• Replace "your_username", "your_password", and "your_database" with your
PostgreSQL credentials.
Step 5: Create Entities
• Create a src/entities/User.ts file:
Step 6: Create Repository
• Create a src/repositories/UserRepository.ts file:
Step 7: Create an Express App
• Create a src/index.ts file:
Step 8: Run the Application
• Compile TypeScript and start the application:
Module 5 Web Programing Setting Up Postgres.pptx

Module 5 Web Programing Setting Up Postgres.pptx

  • 1.
  • 2.
    • Setting UpPostgres and a Repository Layer with TypeORM • Technical requirements • Setting up our Postgres database • Understanding object relational mappers by using TypeORM • Building our repository layer using Postgres and TypeORM
  • 3.
    What is data •Data can come in the form of text, observations, figures, images, numbers, graphs, or symbols. • For example, data might include individual prices, weights, addresses, ages, names, temperatures, dates, or distances. • Data is a raw form of knowledge and, on its own, doesn't carry any significance or purpose.
  • 4.
    What Is aDatabase? • A database is an organized collection of structured information, or data, typically stored electronically in a computer system. • Some real-life examples of databases include student database, employee database, eCommerce, healthcare, online banking systems, hotel booking systems, airline reservation systems.
  • 7.
    Types of Databases •Hierarchical Databases. • Relational Databases. • Network Databases. • Object oriented databases
  • 8.
    Types of Databases •Hierarchical Databases. data model in which the data are organized into a tree-like structure
  • 9.
    A relational databaseis a type of database that stores and provides access to data points
  • 10.
    • Network Databases.a database model where numerous records or files can link to multiple owner files
  • 11.
    object-oriented database (OOD) •An object-oriented database (OOD) is a database system that can work with complex data objects — that is, objects that mirror those used in object-oriented programming languages. In object-oriented programming (OOP), everything is an object.
  • 13.
    What Is aDatabase Management System? • Database Management Systems (DBMS) are software systems used to store, retrieve, and run queries on data. • A DBMS serves as an interface between an end-user and a database, allowing users to create, read, update, and delete data in the database. • Eg. MySql, Oracle, PostgreSQL, Access, MongoDB
  • 14.
    SQL • What isSQL? • SQL stands for Structured Query Language • SQL lets you access and manipulate databases
  • 15.
    What Can SQLdo? • SQL can execute queries against a database • SQL can retrieve data from a database • SQL can insert records in a database • SQL can update records in a database • SQL can delete records from a database • SQL can create new databases • SQL can create new tables in a database
  • 16.
    What is PostgreSQLand why it is used? • It is a highly stable database management system, backed by more than 20 years of community development which has contributed to its high levels of resilience, integrity, and correctness.
  • 17.
    The minimum hardwarerequired to install and run PostgreSQL is: • 1 GHz processor. • 2 GB of RAM. • 512 MB of HDD.
  • 18.
    Who uses PostgreSQL? TopCompanies using PostgreSQL Company Name Website Revenue Netflix www.netflix.co m $24.9 Billion Uber auth.uber.com $14.6 Billion Instacart www.instacart.c om $1.8 Billion LaunchDarkly launchdarkly.co m $57 Million
  • 19.
    Benefits of PostgreSQL •In other words, it offers atomicity, consistency, isolation and durability features. PostgreSQL's advanced features include stored procedures, triggers, user-defined functions, transactions and replication. • PostgreSQL provides enterprise-grade scalability performance, availability and functionality. Thus, you can deploy PostgreSQL in a distributed architecture, which can handle large volumes of data. • Another important feature of PostgreSQL is that it’s open source, which makes it an affordable solution for businesses to keep costs low. • PostgreSQL has an excellent track record of reliability and data security. • It’s been used in production by customers for decades and is trusted by many organizations and businesses worldwide.
  • 20.
    How to setupthe PostgreSQL? 1.Download the installer from the official PostgreSQL website: https://www.postgresql.org/download/windows/ 2.Run the installer and follow the instructions. 3.Start the PostgreSQL Service: 4.Windows: PostgreSQL service should start automatically after installation. 5.Access PostgreSQL Shell: 6.Windows: Open the SQL Shell (psql) from the PostgreSQL folder in the Start menu. 7.Change Password for the PostgreSQL User:
  • 21.
    8. Windows: Openthe SQL Shell (psql). 9. CREATE DATABASE your_database; 10. Switch to the New Database: 11. Create a User for the Database: 12. CREATE USER your_user WITH PASSWORD 'your_password'; 13. GRANT ALL PRIVILEGES ON DATABASE your_database TO your_user; 14. Exit the PostgreSQL ShellConnect to PostgreSQL: 15. You can now connect to PostgreSQL using a database client or your preferred programming language.For example, using the psql command- line client:
  • 22.
    Class • A classis a template for creating objects in program. • Example: Car. Object • The object is an instance of a class. • Example: Jaguar, BMW, Tesla, etc.
  • 24.
    Object Relational Mapper(ORM) • ORM stands for Object-Relational Mapping. It is a programming technique that allows you to interact with a relational database using an object-oriented programming language. • The main purpose of an ORM is to bridge the gap between the relational model of a database and the object-oriented model of a programming language. With an ORM, you can interact with the database using objects and their methods, rather than writing raw SQL queries.
  • 25.
    TypeScript is anopen-source programming language developed by Microsoft. TypeScript offers numerous benefits for developers • Improved Developer Experience: • Enhanced Code Quality: • Large and complex web applications: • API development: • Reduced runtime errors: • Improved performance:
  • 26.
    • TypeORM isan Object-Relational Mapping (ORM) library for TypeScript • It enables developers to interact with relational databases using TypeScript • TypeORM supports a variety of database management systems, including PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server.
  • 27.
    Building our repositorylayer using Postgres and TypeORM • Building a repository layer using PostgreSQL and TypeORM involves setting up a database, defining entities, creating a repository, and integrating TypeORM into your project. • Below is a step-by-step guide using Node.js and TypeScript, assuming you have Node.js and npm installed.
  • 28.
    Step 1: ProjectSetup • Create a new project and initialize it with npm: Step 2: TypeScript Configuration • Create a tsconfig.json file in the root directory: Step 3: PostgreSQL Configuration • Create a PostgreSQL database and note down the connection details (host, username, password, database name). Step 4: TypeORM Configuration • Create an ormconfig.json file in the root directory:
  • 29.
    • Replace "your_username","your_password", and "your_database" with your PostgreSQL credentials. Step 5: Create Entities • Create a src/entities/User.ts file: Step 6: Create Repository • Create a src/repositories/UserRepository.ts file: Step 7: Create an Express App • Create a src/index.ts file: Step 8: Run the Application • Compile TypeScript and start the application: