This repository has been archived by the owner on Mar 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Database handler #34
Open
Mattemagikern
wants to merge
15
commits into
master
Choose a base branch
from
DatabaseHandler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Database handler #34
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d256900
cluster implemented
Mattemagikern a273656
app.js formatting
eHammarstrom 01125d8
Update app.js
Mattemagikern 878c53a
Created a Database handler.
Mattemagikern a9c3db4
adds missed files from last commit
Mattemagikern a26046b
Sequalize implementation begin
Mattemagikern f4ea467
updated user to specifications
Mattemagikern 2d94de6
Created Post table
Mattemagikern 730f930
Added a create roles migration
Oscar-Rydh 0c10bf2
Creatod database table tags
Mattemagikern 7715bb1
Added user roles migration
Oscar-Rydh fa079cc
updated tables
Mattemagikern e094766
updated tables
Mattemagikern fcc0235
Merge branch 'DatabaseHandler' of github.com:Dsek-LTH/dAPI into Datab…
Mattemagikern 5f3ccbc
cleaning up branch
Mattemagikern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var mysql = require('mysql'); | ||
// the Database connection information goes here | ||
var dbConfig = { | ||
host: "", | ||
user: "", | ||
password: "", | ||
database: "" | ||
}; | ||
|
||
var con; | ||
|
||
function query(sql,values,callback){ | ||
con = mysql.createConnection(dbConfig); | ||
con.query(sql, [values], function (err, result,fields) { | ||
if(err) | ||
throw err; | ||
else | ||
callback(result); | ||
}); | ||
con.end(); | ||
} | ||
|
||
module.exports = { | ||
|
||
exampleUsage: function(body,callback){ | ||
var sql = ""; | ||
var params = []; | ||
query(sql,param,callback); | ||
}, | ||
|
||
createUser : function(body,callback){ | ||
|
||
}, | ||
|
||
getUser : function (params,callback) { | ||
var sql = "select * from user where id = ?"; | ||
var values= [params.id]; | ||
console.log("Pre query") | ||
query(sql,values,callback); | ||
}, | ||
|
||
GiveRoleToUser : function (body,callback) { | ||
|
||
}, | ||
|
||
CreatePost : function (body,callback) { | ||
|
||
}, | ||
|
||
AddTagToPost : function (body,callback) { | ||
|
||
} | ||
} |
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 was deleted.
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 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var db = require('../Database'); | ||
|
||
/* GET a user from the database. */ | ||
router.get('/:id', function(req, res, next) { | ||
db.getUser(req.query,function (callback) { | ||
res.writeHead(200,{'Content-Type':'application/json'}); | ||
res.end(JSON.stringify(callback)); | ||
}) | ||
}); | ||
|
||
module.exports = router; |
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
Empty file.
This file was deleted.
Oops, something went wrong.
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,8 +1,21 @@ | ||
const assert = require('assert'); | ||
const db = require('../Database'); | ||
|
||
describe('Array', function() { | ||
describe('#indexOf()', function() { | ||
it('should return -1 when the value is not present', function() { | ||
assert.equal(-1, [1,2,3].indexOf(4)); | ||
}); | ||
describe('#indexOf()', function() { | ||
it('should return -1 when the value is not present', function() { | ||
assert.equal(-1, [1,2,3].indexOf(4)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#Database.js', function () { | ||
it('Should return a row containing all the information of a user', function () { | ||
var query = {"id":"1"}; | ||
var answer = 0; | ||
db.getUser(query,function (callback) { | ||
answer = callback; | ||
}); | ||
assert.equal(1,answer); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tables should have plural names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1