-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
30 deletions.
There are no files selected for viewing
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
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
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,100 @@ | ||
var fs = require('fs'); | ||
var util = require('util'); | ||
var mongodb = require('mongodb'); | ||
|
||
var MongoClient = require('mongodb').MongoClient; | ||
assert = require('assert'); | ||
|
||
// Connection url | ||
var url = 'mongodb://localhost'; | ||
|
||
/* ---- Anime insertion ---- */ | ||
// Inserts many anime | ||
var insertAnime = function(info, db, callback) { | ||
|
||
var collection = db.collection('anime'); | ||
|
||
// Insert some documents | ||
collection.insertMany([ | ||
info | ||
], function(err, result) { | ||
assert.equal(err, null); | ||
assert.equal(1, result.result.n); | ||
assert.equal(1, result.ops.length); | ||
callback(result); | ||
}); | ||
}; | ||
|
||
// Wrapper function to insert data externally | ||
var insertAnimeWrapper = function(info) { | ||
MongoClient.connect(url, function(err, client) { | ||
|
||
var db = client.db('Lightning'); | ||
|
||
assert.equal(null, err); | ||
insertAnime(info, db, function() { | ||
client.close(); | ||
}); | ||
}); | ||
}; | ||
|
||
/* ---- Anime Filter ---- */ | ||
// Select anime(s) with the given condition | ||
var filterAnime = function(condition, db, callback) { | ||
|
||
var collection = db.collection('anime'); | ||
|
||
// Find some documents | ||
collection.find(condition).toArray(function(err, docs) { | ||
assert.equal(err, null); | ||
callback(docs); | ||
}); | ||
}; | ||
|
||
|
||
// Wrapper function returns a single key | ||
var filterAnimeWrapper = function(condition, callback) { | ||
MongoClient.connect(url, function(err, client) { | ||
|
||
var db = client.db('Lightning'); | ||
|
||
assert.equal(null, err); | ||
filterAnime(condition, db, function(result) { | ||
client.close(); | ||
if (callback){ | ||
callback(result); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
var findAllAnime = function(db, callback) { | ||
|
||
var collection = db.collection('anime'); | ||
|
||
collection.find({}).toArray(function(err, docs) { | ||
assert.equal(err, null); | ||
callback(docs); | ||
}); | ||
}; | ||
|
||
var findAllAnimeWrapper = function(callback) { | ||
MongoClient.connect(url, function(err, client) { | ||
|
||
var db = client.db('Lightning'); | ||
|
||
assert.equal(null, err); | ||
findAllAnime(db, function(results) { | ||
client.close(); | ||
if(callback) | ||
callback(results); | ||
}); | ||
}); | ||
}; | ||
|
||
|
||
// so we can externally call these function | ||
exports.insertAnime = insertAnimeWrapper; | ||
exports.filterAnime = filterAnimeWrapper; | ||
exports.findAllAnime = findAllAnimeWrapper; |
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
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,37 @@ | ||
doctype html | ||
// | ||
Story by HTML5 UP | ||
html5up.net | @ajlkn | ||
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license) | ||
html | ||
head | ||
title #{title} | ||
meta(charset='utf-8') | ||
meta(name='viewport', content='width=device-width, initial-scale=1') | ||
link(rel='stylesheet', href='css/main.css') | ||
body | ||
// Seven | ||
section.wrapper.style1.align-center | ||
.inner.medium | ||
h2 Anime Post | ||
form | ||
.field.half.first | ||
label(for='name') Anime Title | ||
input#name(type='text', name='name', value='') | ||
.field.half | ||
label(for='rating') Rating | ||
input#rating(type='text', name='rating', value='') | ||
.field.half.first | ||
label(for='fav_char') Favorite Character | ||
input#fav_char(type='text', name='rating', value='') | ||
.field | ||
label(for='review') Review | ||
p#charcount | ||
textarea#review(name='review') | ||
ul.actions | ||
li | ||
button#submit(type='submit', onclick="animesubmit()", value='Post') Post | ||
|
||
|
||
|
||
|
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
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
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
extends layout | ||
|
||
block content | ||
h1= message | ||
h2= error.status | ||
pre #{error.stack} | ||
p #{title} #{reason} |