Permalink
Browse files

updated reposity

  • Loading branch information...
mlemieux47 committed Dec 2, 2019
0 parents commit e9a6727eec321102fe975a6e0538544190d4b78c
Showing 2,996 changed files with 384,310 additions and 0 deletions.
@@ -0,0 +1,2 @@
.node_modules/
.DS_Store
68 app.js
@@ -0,0 +1,68 @@
let express = require('express')
let database = require('./database.js')
let app = express()

app.use(express.json());

app.get('/bands', (request, response) =>{
const getBandQuery = "SELECT band_name FROM bands"

database.all(getBandQuery, (error, rows)=>{
if(error) {
console.error("Select bands failed")
response.json({error: error})
}
else {
console.log("Select bands succeded")
response.json(rows)
}
})
})

app.post('/bands', (request, response)=> {
const bandName = request.body.band_name
if (bandName != "Creed") {
const insertBandsQuery =
'INSERT INTO bands VALUES (?)';

database.run(insertBandsQuery, [bandName], error => {
if(error) console.error(newError("Insert into bands failed."));
else {
console.log('Insert ${bandName} succeeded');
response.json({ msg: 'Insert ${bandName} succeeded'});
}
})
}
else {
response.json('CREED SUCKS')
}
})

app.delete('/band/:bandName', (request, response)=> {
const bandName = request.params.bandName
const getBandByIdQuery = 'SELECT oid FROM bands WHERE band_name = ?'
database.all(getBandByIdQuery, [bandName], (error, rows)=>{
if(error){
console.error("Get band by ID failed")
response.json({error:error})
}
else if(rows.length > 1) {
console.error("Delete duplicate band name")
response.json({error: "Duplicate band name"})
})

const bandId = row.oid
const deleteBandQuery = `DELETE FROM bands WHERE ? = oid`
database.run(deleteBandQuery,[bandId], error=> {
if(error){
console.error("Delete from bands failed")
response.json({error: error})
}
else {
console.log("Insert into bands succeeded")
response.json({success: true})
}
})
})

module.exports = app
BIN +12 KB database.db
Binary file not shown.
@@ -0,0 +1,18 @@
let sqlite3 = require('sqlite3')
let database = new sqlite3.Database('./database.db') // not creating a new database just creating a connection to the database file -jscprit refernce to that database

const createBandTableQuery =
"CREATE TABLE IF NOT EXISTS bands (band_name TEXT)"
const createAlbumTableQuery =
"CREATE TABLE IF NOT EXISTS albums (album_name TEXT, band_id INTERGER)"

database.run(createBandTableQuery, error=>{
if(error) console.error(new Error("Create Band Table failed"))
else console.log("Create Band Table succeeded")
})
database.run(createAlbumTableQuery, error=> {
if(error) console.error(new Error("Create Album Table failed"))
else console.log("Create Album Table succeeded")
})

module.exports = database
@@ -0,0 +1,6 @@
let app = require('./app.js')
app.listen(9000)

//when you do an http request with the same '/' you are getting two piece of middleware ("first" & "second") - it will go to "first" first becuase express wis top down.
//when you specifc "next()" it tells it to go to the next
//response.send() - will end the get request - use response.write() when you want to keep going

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit e9a6727

Please sign in to comment.