default to using order by desc on created_at (if no order specified)
This commit is contained in:
parent
7fcfbc4d83
commit
c59c0f5e8f
|
@ -147,6 +147,10 @@ function wrap(db, dir, dbsMap) {
|
||||||
|
|
||||||
dir.indices.forEach(normalizeColumn);
|
dir.indices.forEach(normalizeColumn);
|
||||||
DB._indices = dir.indices;
|
DB._indices = dir.indices;
|
||||||
|
DB._indicesMap = {};
|
||||||
|
DB._indices.forEach(function (col) {
|
||||||
|
DB._indicesMap[col.name] = col;
|
||||||
|
});
|
||||||
|
|
||||||
function simpleParse(row) {
|
function simpleParse(row) {
|
||||||
if (!row) {
|
if (!row) {
|
||||||
|
@ -251,12 +255,16 @@ function wrap(db, dir, dbsMap) {
|
||||||
|
|
||||||
if (params) {
|
if (params) {
|
||||||
if (params.orderBy) {
|
if (params.orderBy) {
|
||||||
sql += " ORDER BY \"" + db.escape(snakeCase(params.orderBy) + "\" ");
|
sql += " ORDER BY \"" + db.escape(snakeCase(params.orderBy)) + "\" ";
|
||||||
if (params.orderByDesc) {
|
if (params.orderByDesc) {
|
||||||
sql += 'DESC ';
|
sql += "DESC ";
|
||||||
}
|
}
|
||||||
|
} else if (DB._indicesMap.updated_at) {
|
||||||
|
sql += " ORDER BY \"updated_at\" DESC ";
|
||||||
|
} else if (DB._indicesMap.created_at) {
|
||||||
|
sql += " ORDER BY \"created_at\" DESC ";
|
||||||
}
|
}
|
||||||
if (params.limit) {
|
if (isFinite(params.limit)) {
|
||||||
sql += " LIMIT " + parseInt(params.limit, 10);
|
sql += " LIMIT " + parseInt(params.limit, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue