Skip to content

Commit

Permalink
Update in Database configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrathore1 committed Feb 3, 2024
1 parent 8a05272 commit 8bf8332
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PostgreSQL credentials
PG_PORT=5432
PG_USER=dsrathore
PG_PWD=dsAdmin123
PG_DB=test
PG_USER=postgres
PG_PWD=secret
PG_DB=postgres
PG_HOST=localhost
1 change: 1 addition & 0 deletions DB/connectDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const client = new Pool({
});


//! When I am trying with Client function then I need to use this connect function
// client.connect(function (err) {
// if (err) throw err;
// console.log('Your database is connected 🎉');
Expand Down
14 changes: 14 additions & 0 deletions DB/queries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// export const getStudents = 'SELECT * FROM STUDENTS';
// export const getStudentByID = 'SELECT * FROM STUDENTS WHERE ID=$1 OR EMAIL_ID=$2';
// export const checkEmailExists = 'SELECT NAME FROM STUDENTS WHERE NAME=$1';
// export const addStudent = 'INSERT INTO STUDENTS (NAME, AGE, DOB, EMAIL_ID) VALUES ($1,$2,$3,$4)';
// export const updateStudent = 'UPDATE STUDENTS SET NAME=$1 WHERE ID=$2';
// export const deleteStudentByID = 'DELETE FROM STUDENTS WHERE ID=$1';


export const getBlog = "SELECT * FROM BLOG"
export const getBlogByID = "SELECT * FROM BLOG WHERE ID=$1 OR SR_NO=$2";

export const postBlogData = "INSERT INTO BLOG (AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT,EMAIL_ID) VALUES($1,$2,$3,$4)"

export const deleteAllData = "TRUNCATE FROM TABLE BLOG";
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2024] [dsrathore]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 0 additions & 24 deletions Queries/query.sql

This file was deleted.

28 changes: 28 additions & 0 deletions Query/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Active: 1706869359623@@127.0.0.1@5432@postgres

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS BLOG (
ID UUID PRIMARY KEY DEFAULT uuid_generate_v4 (), SR_NO SERIAL, AUTHOR VARCHAR(90) NOT NULL, TITLE VARCHAR(90) NOT NULL, BLOG_DESCRIPTION TEXT, BLOG_CONTENT TEXT, CREATED_AT TIMESTAMP DEFAULT NOW(), EMAIL_ID VARCHAR(90) UNIQUE NOT NULL
);

SELECT * FROM BLOG;

TRUNCATE TABLE BLOG;

DROP TABLE BLOG;

INSERT INTO
BLOG (
AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT, EMAIL_ID
)
VALUES (
'AJI', 'DevOps Life cycle', 'The DevOps lifecycle is an iterative and collaborative process that integrates automation and feedback to deliver high-quality software, tailored to meet business and user requirements.', 'DevOps Lifecycle is the set of phases that includes DevOps for taking part in Development and Operation group duties for quicker software program delivery. DevOps follows positive techniques that consist of code, building, testing, releasing, deploying, operating, displaying, and planning. DevOps lifecycle follows a range of phases such as non-stop development, non-stop integration, non-stop testing, non-stop monitoring, and non-stop feedback. Each segment of the DevOps lifecycle is related to some equipment and applied sciences to obtain the process. Some of the frequently used tools are open source and are carried out primarily based on commercial enterprise requirements. DevOps lifecycle is effortless to manipulate and it helps satisfactory delivery.',
'AJI123@GMAIL.COM'
);

-- DELETE FROM BLOG
-- WHERE
-- SR_NO = 'd2e9850e-5a4a-407f-b328-5172c3bb3108';

-- ALTER TABLE BLOG ADD UNIQUE (NAME, EMAIL, PHONE_NUMBER);
57 changes: 34 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# 📝 My Awesome Blog Website

## Getting Started
Welcome to my fantastic Blog website project! 🎉 In this project, I've utilized a variety of cutting-edge tools and technologies to create an efficient and secure platform for sharing my thoughts and ideas.

## Technologies Used

### Kubernetes (K8s) 🚀
Kubernetes is the backbone of my deployment strategy. It enables me to orchestrate containerized applications effortlessly, ensuring scalability, resilience, and efficient resource utilization.

First, run the development server:
### Docker 🐳
Docker allows me to containerize my application, providing consistency across different environments and simplifying the deployment process. With Docker, I can package my blog website and its dependencies into a single unit, making it easy to deploy anywhere.

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
### Trivy 🕵️‍♂️
Security is paramount for my blog website. Trivy helps me scan my Docker containers and images for vulnerabilities, ensuring that my application is protected against potential threats. By regularly scanning for vulnerabilities, I can stay ahead of security risks and maintain the integrity of my website.

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
### GitHub Actions 🤖
GitHub Actions automates my CI/CD pipeline, streamlining the process of building, testing, and deploying my blog website. With GitHub Actions, I can automate repetitive tasks and ensure that each code change is thoroughly tested and deployed with confidence.

You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.
### AWS ☁️
Amazon Web Services (AWS) provides the infrastructure for hosting my blog website. With services like EC2, S3, and RDS, I can ensure high availability, scalability, and reliability for my application. AWS also offers a wide range of additional services that enhance the performance and security of my website.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
### SSL Certificates by Caddy 🔒
Security is non-negotiable for my blog website. With SSL certificates provided by Caddy, I can encrypt communication between my users and the server, ensuring that sensitive data remains confidential. Caddy automates the process of obtaining and renewing SSL certificates, making it easy to maintain a secure connection.

## Learn More
### Next.js with App Router 🔄
For creating my blog website, I've chosen Next.js with its powerful App Router feature. Next.js provides server-side rendering out of the box, enabling fast page loads and optimal SEO performance. The App Router simplifies navigation and dynamic routing, making it easy to create a seamless browsing experience for my visitors.

### PostgreSQL 🐘
PostgreSQL serves as the database for my blog website. It offers robust features, including ACID compliance, full support for JSON, and powerful indexing, making it an excellent choice for managing and querying structured data. With PostgreSQL, I can ensure data integrity and scalability for my application.

## Getting Started

To learn more about Next.js, take a look at the following resources:
To get started with my blog website, follow these steps:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
1. Clone the repository: `git clone https://github.com/yourusername/your-blog-website.git`
2. Navigate to the project directory: `cd your-blog-website`
3. Install dependencies: `npm install`
4. Start the development server: `npm run dev`
5. Open your browser and visit `http://localhost:3000` to view the website locally.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Contributing

## Deploy on Vercel
Contributions are welcome! If you have any suggestions, feature requests, or bug reports, feel free to open an issue or submit a pull request. Together, we can make this blog website even more awesome! 😊

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
## License

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
41 changes: 41 additions & 0 deletions app/api/blog/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { client } from "@/DB/connectDB";
import { getBlog, postBlogData } from "@/DB/queries";
import { NextResponse as res } from "next/server";

export async function GET(req) {
try {
const result = await client.query(getBlog);
// console.log(result.rows);
return res.json({ message: "Your data", result: result.rows }, { status: 200 });

} catch (error) {
return NextResponse.json({
message: "Internal server error mentioned below 👇🏻",
error: error
}, { status: 500 });
}
}

export async function POST(req) {
try {
const { AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT, EMAIL_ID } = await req.json();
console.log({ AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT, EMAIL_ID });
// return res.json({
// AUTHOR,
// TITLE,
// BLOG_DESCRIPTION,
// BLOG_CONTENT,
// EMAIL_ID
// });

const result = await client.query(postBlogData, [AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT, EMAIL_ID]);
console.log(result.rows);
return res.json({ message: "Imported data successfully", result: result.rows, data: { AUTHOR, TITLE, BLOG_DESCRIPTION, BLOG_CONTENT, EMAIL_ID } });

} catch (error) {
return res.json({
message: "Internal server error mentioned below 👇🏻",
error: error
}, { status: 500 });
}
}
5 changes: 1 addition & 4 deletions app/api/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { client } from "@/DB/connectDB";
import { NextResponse } from "next/server";

export async function GET(req) {
try {
const result = await client.query('SELECT * FROM TEST_TABLE');
// console.log(result.rows);
return NextResponse.json({ message: "Your data", result: result.rows }, { status: 200 });
return NextResponse.json({ message: "Welcome🎉🎊", GOTO: "http://localhost:3000/api/blog" });

} catch (error) {
return NextResponse.json({
Expand Down
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
api: {
bodyParser: false,
}
};

export default nextConfig;

0 comments on commit 8bf8332

Please sign in to comment.