Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
fix sqlite raw sql return datetime is string format
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 21, 2014
1 parent 9ed3b3a commit 1f2b84e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ CREATE TABLE IF NOT EXISTS `download_total` (
UNIQUE KEY `date_name` (`date`, `name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='module download total info';
-- ALTER TABLE `download_total` CHANGE `name` `name` VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'module name';
-- ALTER TABLE `download_total` CHANGE `date` `date` datetime NOT NULL COMMENT 'YYYY-MM-DD format';
-- ALTER TABLE `download_total` CHANGE `date` `date` datetime NOT NULL COMMENT 'YYYY-MM-DD format';

CREATE TABLE IF NOT EXISTS `module_deps` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
Expand Down
11 changes: 10 additions & 1 deletion services/download_total.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports.getModuleTotal = function* (name, start, end) {
};

exports.plusModuleTotal = function* (data) {
data.date = new Date(data.date);
var row = yield DownloadTotal.find({
where: {
date: data.date,
Expand Down Expand Up @@ -64,10 +65,18 @@ exports.getTotal = function* (start, end) {

function formatRows(rows) {
return rows.map(function (row) {
var date = row.date;
if (typeof date === 'string') {
// sqlite raw datetime is string format ...
date = date.substring(0, 10);
} else {
// mysql return DateTime
date = moment(row.date).format('YYYY-MM-DD');
}
return {
name: row.name,
count: row.count,
date: moment(row.date).format('YYYY-MM-DD'),
date: date,
};
});
}

0 comments on commit 1f2b84e

Please sign in to comment.