Browse Source

Created a sql utility to make it easier for sql operations

pull/4/head
jrtechs 6 years ago
parent
commit
f3aa7e157a
12 changed files with 531 additions and 8 deletions
  1. +8
    -3
      README.md
  2. +7
    -0
      admin/admin.js
  3. +295
    -0
      admin/test.html
  4. +1
    -1
      includes/footer.html
  5. +2
    -1
      includes/header.html
  6. +114
    -0
      includes/sidebar.html
  7. +9
    -0
      includes/sidebar.js
  8. +11
    -0
      posts/category.js
  9. +17
    -0
      posts/posts.js
  10. +7
    -0
      posts/singlePost.js
  11. +6
    -3
      server.js
  12. +54
    -0
      utils/sql.js

+ 8
- 3
README.md View File

@ -1,9 +1,9 @@
# NodeJSBlog
Recreating my wordpress blog in node JS.
##MYSQL Information
## MYSQL Information
'''sql
```SQL
create database blog_name;
use blog_name;
@ -44,4 +44,9 @@ primary key(popular_post_id)
grant all on blog_name.* to blog_user@localhost identified by "password";
'''
```
## Node Dependencies
```bash
npm install mysql
```

+ 7
- 0
admin/admin.js View File

@ -0,0 +1,7 @@
module.exports=
{
main: function(res, fileName)
{
}
};

+ 295
- 0
admin/test.html View File

@ -0,0 +1,295 @@
<!DOCTYPE html>
<html>
<title>W3.CSS Template</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
<style>
body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<body class="w3-light-grey">
<!-- w3-content defines a container for fixed size centered content,
and is wrapped around the whole page content, except for the footer in this example -->
<div class="w3-content" style="max-width:1400px">
<!-- Header -->
<header class="w3-container w3-center w3-padding-32">
<h1><b>MY BLOG</b></h1>
<p>Welcome to the blog of <span class="w3-tag">unknown</span></p>
</header>
<!-- Grid -->
<div class="w3-row">
<!-- Blog entries -->
<div class="w3-col l8 s12">
<!-- Blog entry -->
<div class="w3-card-4 w3-margin w3-white">
<img src="/w3images/woods.jpg" alt="Nature" style="width:100%">
<div class="w3-container">
<h3><b>TITLE HEADING</b></h3>
<h5>Title description, <span class="w3-opacity">April 7, 2014</span></h5>
</div>
<div class="w3-container">
<p>Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed
tellus ut rutrum. Sed vitae justo condimentum, porta lectus vitae, ultricies congue gravida diam non fringilla.</p>
<div class="w3-row">
<div class="w3-col m8 s12">
<p><button class="w3-button w3-padding-large w3-white w3-border"><b>READ MORE &raquo;</b></button></p>
</div>
<div class="w3-col m4 w3-hide-small">
<p><span class="w3-padding-large w3-right"><b>Comments &nbsp;</b> <span class="w3-tag">0</span></span></p>
</div>
</div>
</div>
</div>
<hr>
<!-- Blog entry -->
<div class="w3-card-4 w3-margin w3-white">
<img src="/w3images/bridge.jpg" alt="Norway" style="width:100%">
<div class="w3-container">
<h3><b>BLOG ENTRY</b></h3>
<h5>Title description, <span class="w3-opacity">April 2, 2014</span></h5>
</div>
<div class="w3-container">
<p>Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed
tellus ut rutrum. Sed vitae justo condimentum, porta lectus vitae, ultricies congue gravida diam non fringilla.</p>
<div class="w3-row">
<div class="w3-col m8 s12">
<p><button class="w3-button w3-padding-large w3-white w3-border"><b>READ MORE &raquo;</b></button></p>
</div>
<div class="w3-col m4 w3-hide-small">
<p><span class="w3-padding-large w3-right"><b>Comments &nbsp;</b> <span class="w3-badge">2</span></span></p>
</div>
</div>
</div>
</div>
<!-- END BLOG ENTRIES -->
</div>
<!-- Introduction menu -->
<div class="w3-col l4">
<!-- About Card -->
<div class="w3-card w3-margin w3-margin-top">
<img src="/w3images/avatar_g.jpg" style="width:100%">
<div class="w3-container w3-white">
<h4><b>My Name</b></h4>
<p>Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.</p>
</div>
</div><hr>
<!-- Posts -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Popular Posts</h4>
</div>
<ul class="w3-ul w3-hoverable w3-white">
<li class="w3-padding-16">
<img src="/w3images/workshop.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Lorem</span><br>
<span>Sed mattis nunc</span>
</li>
<li class="w3-padding-16">
<img src="/w3images/gondol.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Ipsum</span><br>
<span>Praes tinci sed</span>
</li>
<li class="w3-padding-16">
<img src="/w3images/skies.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Dorum</span><br>
<span>Ultricies congue</span>
</li>
<li class="w3-padding-16 w3-hide-medium w3-hide-small">
<img src="/w3images/rock.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Mingsum</span><br>
<span>Lorem ipsum dipsum</span>
</li>
</ul>
</div>
<hr>
<!-- Labels / tags -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Tags</h4>
</div>
<div class="w3-container w3-white">
<p><span class="w3-tag w3-black w3-margin-bottom">Travel</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">New York</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">London</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">IKEA</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">NORWAY</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">DIY</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Ideas</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Baby</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Family</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">News</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Clothing</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Shopping</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Sports</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Games</span>
</p>
</div>
</div>
<!-- END Introduction Menu -->
</div>
<!-- END GRID -->
</div>
<!-- END w3-content -->
</div>
<!-- Footer -->
<footer class="w3-container w3-dark-grey w3-padding-32 w3-margin-top">
<button class="w3-button w3-black w3-disabled w3-padding-large w3-margin-bottom">Previous</button>
<button class="w3-button w3-black w3-padding-large w3-margin-bottom">Next &raquo;</button>
<p>Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a></p>
</footer>
</body>
</html>

+ 1
- 1
includes/footer.html View File

@ -1,5 +1,5 @@
<!-- END w3-content -->
</div>
</div>
<!-- Footer -->

+ 2
- 1
includes/header.html View File

@ -29,4 +29,5 @@
</div>
<body class="w3-light-grey">
<div class="w3-content w3-padding-64" style="max-width:1400px">
<div class="w3-content w3-padding-64" style="max-width:1400px">
<div class="w3-row">

+ 114
- 0
includes/sidebar.html View File

@ -0,0 +1,114 @@
<!-- Introduction menu -->
<div class="w3-col l4">
<!-- About Card -->
<div class="w3-card w3-margin w3-margin-top">
<img src="/w3images/avatar_g.jpg" style="width:100%">
<div class="w3-container w3-white">
<h4><b>My Name</b></h4>
<p>Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.</p>
</div>
</div><hr>
<!-- Posts -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Popular Posts</h4>
</div>
<ul class="w3-ul w3-hoverable w3-white">
<li class="w3-padding-16">
<img src="/w3images/workshop.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Lorem</span><br>
<span>Sed mattis nunc</span>
</li>
<li class="w3-padding-16">
<img src="/w3images/gondol.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Ipsum</span><br>
<span>Praes tinci sed</span>
</li>
<li class="w3-padding-16">
<img src="/w3images/skies.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Dorum</span><br>
<span>Ultricies congue</span>
</li>
<li class="w3-padding-16 w3-hide-medium w3-hide-small">
<img src="/w3images/rock.jpg" alt="Image" class="w3-left w3-margin-right" style="width:50px">
<span class="w3-large">Mingsum</span><br>
<span>Lorem ipsum dipsum</span>
</li>
</ul>
</div>
<hr>
<!-- Labels / tags -->
<div class="w3-card w3-margin">
<div class="w3-container w3-padding">
<h4>Tags</h4>
</div>
<div class="w3-container w3-white">
<p><span class="w3-tag w3-black w3-margin-bottom">Travel</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">New York</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">London</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">IKEA</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">NORWAY</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">DIY</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Ideas</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Baby</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Family</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">News</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Clothing</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Shopping</span>
<span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Sports</span> <span class="w3-tag w3-light-grey w3-small w3-margin-bottom">Games</span>
</p>
</div>
</div>
<!-- END Introduction Menu -->
</div>

+ 9
- 0
includes/sidebar.js View File

@ -0,0 +1,9 @@
const utils = require('../utils/utils.js');
module.exports=
{
main: function(res, fileName)
{
utils.include(res,"includes/sidebar.html");
}
};

+ 11
- 0
posts/category.js View File

@ -0,0 +1,11 @@
module.exports=
{
main: function(res, fileName)
{
}
};

+ 17
- 0
posts/posts.js View File

@ -0,0 +1,17 @@
const utils = require('../utils/utils.js');
module.exports=
{
/**
* Function which parses a url and displays appropriate post
*
* @param res
* @param fileName request url
*/
main: function(res, requestURL)
{
require("../includes/sidebar.js").main(res, requestURL);
}
};

+ 7
- 0
posts/singlePost.js View File

@ -0,0 +1,7 @@
module.exports=
{
main: function(res, fileName)
{
}
};

+ 6
- 3
server.js View File

@ -10,10 +10,10 @@ const http = require('http');
const url = require('url');
const includes = require('./includes/includes.js');
http.createServer(function (req, res)
http.createServer(function (request_url, res)
{
var q = url.parse(req.url, true);
var filename = "." + q.pathname;
var q = url.parse(request_url.url, true);
var filename = q.pathname;
//prints header
includes.printHeader(res);
@ -21,6 +21,7 @@ http.createServer(function (req, res)
if(filename.includes("/category"))
{
//categories or view a category page
}
else if(filename.includes("/downloads/"))
{
@ -30,10 +31,12 @@ http.createServer(function (req, res)
else if(filename.includes("/admin"))
{
//admin page
}
else
{
//normal blog entry
require("./posts/posts.js").main(res, filename);
}
//includes footer file

+ 54
- 0
utils/sql.js View File

@ -0,0 +1,54 @@
const mysql = require('mysql');
const con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
module.exports=
{
/**
* Function used to query the database for records
*
* @param sqlStatement
* @returns {Array}
*/
fetch : function(sqlStatement)
{
con.connect(function(err)
{
if (err) throw err;
con.query(sqlStatement, function (err, result)
{
if (err) throw err;
return result;
});
});
return [];
},
/**
* Function used to use insert statements into the database
*
* @param sqlStatement
* @return the id of the new record - if there is one
*/
insert : function(sqlStatement)
{
con.connect(function(err)
{
if (err) throw err;
con.query(sqlStatement, function (err, result)
{
if (err) throw err;
return result.insertId;
});
});
return 0;
}
};

Loading…
Cancel
Save