forked from 205CDE-1819JANMAY/TEACHING-MATERIALS
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge branch 'master' of https://github.coventry.ac.uk/205CDE-1819JAN…
- Loading branch information
Showing
35 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"Title", "ISBN13", "Author", "Publisher", "Year" | ||
"Learning Node: Moving to the Server-Side", 9781491943120, "Shelley Powers", "O′Reilly", 2016 | ||
"Web Development with Node and Express: Leveraging the JavaScript Stack",9781491949306, "Ethan Brown", "O'Reilly", 2014 | ||
"JavaScript: The Good Parts", 9780596517748, "Douglas Crockford", "O′Reilly", 2008 | ||
"Understanding Ecmascript 6", 9781593277574, "Nicholas Zakus", "No Starch Press", 2016 | ||
"The Principles of Object-Oriented JavaScript", 9781593275402, "Nicholas C. Zakas", "No Starch Press", 2014 | ||
"Using SQLite", 9780596521189, "Jay A. Kreibich", "O'Reilly", 2010 | ||
"Getting Started with SQL: A hands-on approach for beginners", 9781491938614, "Thomas Nield", "O'Reilly", 2016 | ||
"The Language of SQL", 9780134658254, "Larry Rockoff", "Addison Wesley", 2016 | ||
"Node.js, MongoDB and Angular Web Development", 9780134655536, "Brad Dayley", "Addison Wesley", 2017 | ||
"MongoDB: The Definitive Guide", 9781449344689, "Kristina Chodorow", "O'Reilly", 2013 | ||
"Graph Databases", 9781491930892, "Ian Robinson, Jim Webber, Emil Eifrem", "O'Reilly", 2015 | ||
"HTML5 In Easy Steps", 9781840787542, "Mike McGrath", "In Easy Steps Limited", 2017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
INSERT INTO books(title, isbn, description) | ||
VALUES( | ||
"Graph Databases", | ||
9781491930892, | ||
"Discover how graph databases can help you manage and query highly connected data. | ||
With this practical book, you’ll learn how to design and implement a graph database | ||
that brings the power of graphs to bear on a broad range of problem domains. | ||
Whether you want to speed up your response to user queries or build a database that | ||
can adapt as your business evolves, this book shows you how to apply the schema-free | ||
graph model to real-world problems. | ||
This second edition includes new code samples and diagrams, using the latest Neo4j | ||
syntax, as well as information on new functionality. Learn how different | ||
organizations are using graph databases to outperform their competitors. With this | ||
book’s data modeling, query, and code examples, you’ll quickly be able to implement | ||
your own solution." | ||
); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const Koa = require('koa') | ||
const Router = require('koa-router') | ||
const stat = require('koa-static') | ||
const Database = require('sqlite-async') | ||
const handlebars = require('koa-hbs-renderer') | ||
|
||
const app = new Koa() | ||
const router = new Router() | ||
app.use(stat('public')) | ||
|
||
app.use(handlebars({ paths: { views: `${__dirname}/views` } })) | ||
app.use(router.routes()) | ||
|
||
const port = 8080 | ||
const dbName = 'bookshop.db' | ||
|
||
router.get('/', async ctx => { | ||
try { | ||
console.log('/') | ||
const sql = 'SELECT id, title FROM books;' | ||
const db = await Database.open(dbName) | ||
const data = await db.all(sql) | ||
await db.close() | ||
console.log(data) | ||
await ctx.render('home', {title: 'Favourite Books', books: data}) | ||
} catch(err) { | ||
ctx.body = err.message | ||
} | ||
}) | ||
|
||
/* router.get('/', async ctx => { | ||
try { | ||
let sql = 'SELECT id, title FROM books;' | ||
let querystring = '' | ||
console.log(ctx.query.q) | ||
if(ctx.query !== undefined && ctx.query.q !== undefined) { | ||
sql = `SELECT id, title FROM books | ||
WHERE upper(title) LIKE "%${ctx.query.q}%" | ||
OR upper(description) LIKE upper("%${ctx.query.q}%");` | ||
querystring = ctx.query.q | ||
} | ||
const db = await Database.open(dbName) | ||
const data = await db.all(sql) | ||
await db.close() | ||
console.log(data) | ||
await ctx.render('newindex', {books: data, query: querystring}) | ||
} catch(err) { | ||
ctx.body = err.message | ||
} | ||
}) */ | ||
|
||
router.get('/details/:id', async ctx => { | ||
try { | ||
console.log(ctx.params.id) | ||
const sql = `SELECT * FROM books WHERE id = ${ctx.params.id};` | ||
const db = await Database.open(dbName) | ||
const data = await db.get(sql) | ||
await db.close() | ||
console.log(data) | ||
await ctx.render('details', data) | ||
} catch(err) { | ||
ctx.body = err.message | ||
} | ||
}) | ||
|
||
router.get('/form', async ctx => await ctx.render('form')) | ||
|
||
router.post('/add', async ctx => { | ||
try { | ||
console.log(ctx.request.body) | ||
const body = ctx.request.body | ||
const sql = `INSERT INTO books(title, isbn, description) | ||
VALUES("${body.title}", "${body.isbn}", "${body.description}";` | ||
console.log(sql) | ||
const db = await Database.open(dbName) | ||
await db.run(sql) | ||
await db.close() | ||
ctx.redirect('/') | ||
} catch(err) { | ||
ctx.body = err.message | ||
} | ||
}) | ||
|
||
module.exports = app.listen(port, () => console.log(`listening on port ${port}`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "bookshop", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"server": "node index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"koa": "^2.7.0", | ||
"koa-hbs-renderer": "^1.2.0", | ||
"koa-router": "^7.4.0", | ||
"koa-static": "^5.0.0", | ||
"sqlite-async": "^1.0.11" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My Favourite Books</title> | ||
<link href="css/style.css" type="text/css" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
<h1>{{title}}</h1> | ||
<h2>ISBN: {{isbn}}</h2> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<!doctype html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Add a Book</title> | ||
<meta name="description" content="form to add new books"> | ||
<meta name="author" content="Mark Tyers"> | ||
</head> | ||
<body> | ||
<h1>Add a Book</h1> | ||
<form action="/add" method="post"> | ||
<p>Book Title:<br /><input type="text" name="title" placeholder="book title" value="" autofocus></p> | ||
<p>ISBN13:<br /><input type="number" name="isbn" placeholder="ISBN13 number" value="" maxlength="13" autocomplete="off"></p> | ||
<p>Description:<br /><textarea name="description"></textarea></p> | ||
<p><input type="submit" value="Add"></p> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>My Favourite Books</title> | ||
<link href="css/style.css" type="text/css" rel="stylesheet" /> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>{{title}}</h1> | ||
</header> | ||
<p>The following books will help you in this module:</p> | ||
<ul> | ||
{{#each books}} | ||
<li>{{this.title}}</li> | ||
{{/each}} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
<!doctype html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Bookshop</title> | ||
<meta name="description" content="Google Book Search"> | ||
<meta name="author" content="Mark Tyers"> | ||
</head> | ||
<body> | ||
<h1>Bookshop</h1> | ||
<form action="/" method="get"> | ||
<input type="text" name="q" value="{{query}}"> | ||
<input type="submit" value="Search"> | ||
</form> | ||
<ol> | ||
{{#if query}} | ||
<p>{{query}}</p> | ||
{{/if}} | ||
{{#each books}} | ||
<li>{{this.title}}</li> | ||
{{/each}} | ||
</ol> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.