Code files

This commit is contained in:
Akhil
2017-07-31 11:33:31 +05:30
parent 073a63ebdd
commit b9ae409ec0
801 changed files with 17535 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
const mysql = require('mysql')
const params = {
author: process.argv[2],
quote: process.argv[3]
}
const db = mysql.createConnection({
user: 'root',
//password: 'pw-if-set',
//debug: true
})
db.query('CREATE DATABASE quotes')
db.query('USE quotes')
db.query(`
CREATE TABLE quotes.quotes (
id INT NOT NULL AUTO_INCREMENT,
author VARCHAR ( 128 ) NOT NULL,
quote TEXT NOT NULL, PRIMARY KEY ( id )
)
`)
const ignore = new Set([
'ER_DB_CREATE_EXISTS',
'ER_TABLE_EXISTS_ERROR'
])
db.on('error', (err) => {
if (ignore.has(err.code)) return
throw err
})
if (params.author && params.quote) {
db.query(`
INSERT INTO quotes.quotes (author, quote)
VALUES (?, ?);
`, [params.author, params.quote])
}
if (params.author) {
db.query(`
SELECT * FROM quotes
WHERE author LIKE ${db.escape(params.author)}
`).on('result', ({author, quote}) => {
console.log(`${author} ${quote}`)
})
}
db.end()
+15
View File
@@ -0,0 +1,15 @@
{
"name": "mysql-app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mysql": "^2.12.0"
}
}