Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v2/definitions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ module.exports = function (req, res, next, cb) {
);
}
});
};
};
31 changes: 24 additions & 7 deletions v2/definitions/strat_name_concepts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ module.exports = function (req, res, next, cb) {
JOIN macrostrat.refs ON snm.ref_id = refs.id
*/
}),
params = {};
params = {},
where = [];

if ("all" in req.query) {
// do nothing
} else if (req.query.concept_like) {
where.push("lower(name) ILIKE lower(:name)");
params["name"] = req.query.concept_like + "%";
} else if ("concept_name" in req.query) {
sql += " WHERE name = ANY(:concept_name)";
where.push("name = ANY(:concept_name)");
params["concept_name"] = req.query.concept_name;
} else if (req.query.concept_id || req.query.strat_name_concept_id) {
sql += " WHERE concept_id = ANY(:concept_id)";
where.push("concept_id = ANY(:concept_id)");
if (req.query.concept_id) {
params["concept_id"] = larkin.parseMultipleIds(req.query.concept_id);
} else {
Expand All @@ -43,15 +47,28 @@ module.exports = function (req, res, next, cb) {
);
}
} else if (req.query.strat_name_id) {
sql +=
" WHERE concept_id IN (SELECT concept_id FROM macrostrat.lookup_strat_names WHERE strat_name_id IN (:strat_name_ids))";
where.push("concept_id IN (SELECT concept_id FROM macrostrat.lookup_strat_names WHERE strat_name_id IN (:strat_name_ids))");
params["strat_name_ids"] = larkin.parseMultipleIds(req.query.strat_name_id);
}

// pagination
const lastId = req.query.last_id ? parseInt(req.query.last_id, 10) : null;
const pageSize = req.query.page_size ? parseInt(req.query.page_size, 10) : 5; // defaults to 5

if (req.query.last_id) {
where.push("concept_id > :last_id");
params["last_id"] = lastId;
}

if (where.length > 0) {
sql += " WHERE " + where.join(" AND ");
}

sql += " GROUP BY concept_id, author ORDER BY concept_id";

if ("sample" in req.query) {
sql += " LIMIT 5";
if ("sample" in req.query || req.query.last_id) {
sql += " LIMIT :page_size";
params["page_size"] = pageSize;
}

larkin.queryPg("burwell", sql, params, function (error, result) {
Expand Down
22 changes: 19 additions & 3 deletions v2/definitions/strat_names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function (req, res, next, cb) {
}

var where = [],
params = {};
params = {},
orderBy = [];

if (req.query.rule) {
if (req.query.rule === "down") {
Expand Down Expand Up @@ -123,12 +124,27 @@ module.exports = function (req, res, next, cb) {
FROM macrostrat.lookup_strat_names l
`;

// pagination
const lastId = req.query.last_id ? parseInt(req.query.last_id, 10) : null;
const pageSize = req.query.page_size ? parseInt(req.query.page_size, 10) : 5; // defaults to 5

if (req.query.last_id) {
where.push("strat_name_id > :last_id");
params["last_id"] = lastId;
orderBy.push("strat_name_id ASC");
}

if (where.length > 0) {
sql += " WHERE " + where.join(" AND ");
}

if ("sample" in req.query) {
sql += " LIMIT 5";
if (orderBy.length > 0) {
sql += " ORDER BY " + orderBy.join(", ");
}

if ("sample" in req.query || req.query.last_id) {
sql += " LIMIT :page_size";
params["page_size"] = pageSize;
}

larkin.queryPg("burwell", sql, params, function (error, response) {
Expand Down
5 changes: 5 additions & 0 deletions v2/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@
"retrieve only stratigraphic names linked the specified reference_id (see /defs/refs)",
all: "return all lithostratigraphic names",
format: "Desired output format",
last_id: "integer, used to paginate results. If specified, will return strat_names with an ID greater than last_id",
page_size: "integer, used to paginate results. If specified, will return at most page_size results. Must be paired with last_idd",
},
output_formats: ["json", "csv"],
examples: [
Expand Down Expand Up @@ -746,8 +748,11 @@
parameters: {
concept_id: "unique id",
concept_name: "string specifying concept name",
concept_like: "lithostratigraphic name concept, with open-ended string matching",
all: "return all lithostratigraphic names",
format: "Desired output format",
last_id: "integer, used to paginate results. If specified, will return strat_names with an ID greater than last_id",
page_size: "integer, used to paginate results. If specified, will return at most page_size results. Must be paired with last_idd",
},
output_formats: ["json", "csv"],
examples: ["api/v2/defs/concept_id?all"],
Expand Down