1

Category IDs now ints

This commit is contained in:
Alex Yatskov 2015-03-11 14:41:17 +09:00
parent fad1f34f75
commit 89fefaf5a5
4 changed files with 7 additions and 16 deletions

View File

@ -22,7 +22,6 @@
*/
var mysql = require('mysql');
var uuid = require('node-uuid');
var data = require('./data.json');
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('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 = [
'I prefer quiet places',
@ -70,11 +69,7 @@ var categories = [
];
for (var i = 0, count = categories.length; i < count; ++i) {
conn.query(
'INSERT INTO categories(description, id) VALUES (?, ?)', [
categories[i],
uuid.v1()
]);
conn.query('INSERT INTO categories(description) VALUES (?)', [categories[i]]);
}

View File

@ -13,7 +13,6 @@
"mysql": "^2.5.0",
"underscore": "~1.6.0",
"node-geocoder": "~2.11.0",
"geolib": "~2.0.14",
"node-uuid": "~1.4.2"
"geolib": "~2.0.14"
}
}

View File

@ -13,7 +13,6 @@
"express": "~4.5.1",
"mysql": "^2.5.0",
"underscore": "^1.6.0",
"geolib": "~2.0.14",
"node-uuid": "~1.4.2"
"geolib": "~2.0.14"
}
}

View File

@ -26,7 +26,6 @@
var _ = require('underscore');
var geolib = require('geolib');
var mysql = require('mysql');
var uuid = require('node-uuid');
var pool = null;
@ -224,22 +223,21 @@ function getCategories(callback) {
return {id: row.id, description: row.description};
});
callback(categories.reverse());
callback(categories);
});
}
function addCategory(query, callback) {
var description = query.description.trim();
var id = uuid.v1();
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) {
throw err;
}
callback({
id: id,
id: info.insertId,
description: description,
success: true
});