Category IDs now ints
This commit is contained in:
parent
fad1f34f75
commit
89fefaf5a5
@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var mysql = require('mysql');
|
var mysql = require('mysql');
|
||||||
var uuid = require('node-uuid');
|
|
||||||
var data = require('./data.json');
|
var data = require('./data.json');
|
||||||
|
|
||||||
var conn = mysql.createConnection({
|
var conn = mysql.createConnection({
|
||||||
@ -61,7 +60,7 @@ for (var i = 0, count = data.length; i < count; ++i) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
conn.query('DROP TABLE IF EXISTS categories');
|
conn.query('DROP TABLE IF EXISTS categories');
|
||||||
conn.query('CREATE TABLE categories(description VARCHAR(200) NOT NULL, id VARCHAR(36) NOT NULL PRIMARY KEY)');
|
conn.query('CREATE TABLE categories(description VARCHAR(200) NOT NULL, id INT NOT NULL AUTO_INCREMENT PRIMARY KEY)');
|
||||||
|
|
||||||
var categories = [
|
var categories = [
|
||||||
'I prefer quiet places',
|
'I prefer quiet places',
|
||||||
@ -70,11 +69,7 @@ var categories = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (var i = 0, count = categories.length; i < count; ++i) {
|
for (var i = 0, count = categories.length; i < count; ++i) {
|
||||||
conn.query(
|
conn.query('INSERT INTO categories(description) VALUES (?)', [categories[i]]);
|
||||||
'INSERT INTO categories(description, id) VALUES (?, ?)', [
|
|
||||||
categories[i],
|
|
||||||
uuid.v1()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"mysql": "^2.5.0",
|
"mysql": "^2.5.0",
|
||||||
"underscore": "~1.6.0",
|
"underscore": "~1.6.0",
|
||||||
"node-geocoder": "~2.11.0",
|
"node-geocoder": "~2.11.0",
|
||||||
"geolib": "~2.0.14",
|
"geolib": "~2.0.14"
|
||||||
"node-uuid": "~1.4.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
"express": "~4.5.1",
|
"express": "~4.5.1",
|
||||||
"mysql": "^2.5.0",
|
"mysql": "^2.5.0",
|
||||||
"underscore": "^1.6.0",
|
"underscore": "^1.6.0",
|
||||||
"geolib": "~2.0.14",
|
"geolib": "~2.0.14"
|
||||||
"node-uuid": "~1.4.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var geolib = require('geolib');
|
var geolib = require('geolib');
|
||||||
var mysql = require('mysql');
|
var mysql = require('mysql');
|
||||||
var uuid = require('node-uuid');
|
|
||||||
var pool = null;
|
var pool = null;
|
||||||
|
|
||||||
|
|
||||||
@ -224,22 +223,21 @@ function getCategories(callback) {
|
|||||||
return {id: row.id, description: row.description};
|
return {id: row.id, description: row.description};
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(categories.reverse());
|
callback(categories);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCategory(query, callback) {
|
function addCategory(query, callback) {
|
||||||
var description = query.description.trim();
|
var description = query.description.trim();
|
||||||
var id = uuid.v1();
|
|
||||||
|
|
||||||
if (description) {
|
if (description) {
|
||||||
pool.query('INSERT INTO categories(description, id) VALUES(?, ?)', [description, id], function(err, rows) {
|
pool.query('INSERT INTO categories(description) VALUES(?)', [description], function(err, info) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
id: id,
|
id: info.insertId,
|
||||||
description: description,
|
description: description,
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user