projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More verbose instructions for creating sqlite database
[vchess.git]
/
server
/
models
/
News.js
diff --git
a/server/models/News.js
b/server/models/News.js
index
3f98fd6
..
c10f71f
100644
(file)
--- a/
server/models/News.js
+++ b/
server/models/News.js
@@
-19,7
+19,7
@@
const NewsModel =
"VALUES " +
"(" + Date.now() + "," + uid + ",?)";
db.run(query, content, function(err) {
"VALUES " +
"(" + Date.now() + "," + uid + ",?)";
db.run(query, content, function(err) {
-
return cb(err, {nid: this.lastID
});
+
cb(err, { id: this.lastID
});
});
});
},
});
});
},
@@
-30,32
+30,47
@@
const NewsModel =
const query =
"SELECT * " +
"FROM News " +
const query =
"SELECT * " +
"FROM News " +
- "WHERE id > " + cursor + " " +
+ "WHERE added < " + cursor + " " +
+ "ORDER BY added DESC " +
"LIMIT 10"; //TODO: 10 currently hard-coded
"LIMIT 10"; //TODO: 10 currently hard-coded
- db.all(query, (err,newsList) => {
-
return
cb(err, newsList);
+ db.all(query, (err,
newsList) => {
+ cb(err, newsList);
});
});
},
});
});
},
- update: function(news, cb)
+ getTimestamp: function(cb)
+ {
+ db.serialize(function() {
+ const query =
+ "SELECT added " +
+ "FROM News " +
+ "ORDER BY added DESC " +
+ "LIMIT 1";
+ db.get(query, (err, ts) => {
+ cb(err, ts);
+ });
+ });
+ },
+
+ update: function(news)
{
db.serialize(function() {
let query =
"UPDATE News " +
"SET content = ? " +
"WHERE id = " + news.id;
{
db.serialize(function() {
let query =
"UPDATE News " +
"SET content = ? " +
"WHERE id = " + news.id;
- db.run(query, news.content
, cb
);
+ db.run(query, news.content);
});
},
});
},
- remove: function(id
, cb
)
+ remove: function(id)
{
db.serialize(function() {
const query =
"DELETE FROM News " +
"WHERE id = " + id;
{
db.serialize(function() {
const query =
"DELETE FROM News " +
"WHERE id = " + id;
- db.run(query
, cb
);
+ db.run(query);
});
},
}
});
},
}