diff --git a/pygeoapi/provider/postgresql.py b/pygeoapi/provider/postgresql.py index 08eafd1..d0c0b79 100644 --- a/pygeoapi/provider/postgresql.py +++ b/pygeoapi/provider/postgresql.py @@ -265,6 +265,44 @@ class PostgreSQLProvider(BaseProvider): return feature_collection + def get_previous(self, cursor, identifier): + """ + Query previous ID given current ID + + :param identifier: feature id + + :returns: feature id + """ + sql = 'SELECT {} AS id FROM {} WHERE {}<%s ORDER BY {} DESC LIMIT 1' + cursor.execute(SQL(sql).format( + Identifier(self.id_field), + Identifier(self.table), + Identifier(self.id_field), + Identifier(self.id_field), + ), (identifier,)) + item = cursor.fetchall() + id_ = item[0]['id'] + return id_ + + def get_next(self, cursor, identifier): + """ + Query next ID given current ID + + :param identifier: feature id + + :returns: feature id + """ + sql = 'SELECT {} AS id FROM {} WHERE {}>%s ORDER BY {} LIMIT 1' + cursor.execute(SQL(sql).format( + Identifier(self.id_field), + Identifier(self.table), + Identifier(self.id_field), + Identifier(self.id_field), + ), (identifier,)) + item = cursor.fetchall() + id_ = item[0]['id'] + return id_ + def get(self, identifier): """ Query the provider for a specific @@ -298,6 +336,8 @@ class PostgreSQLProvider(BaseProvider): row_data = cursor.fetchall()[0] feature = self.__response_feature(row_data) + feature['prev'] = self.get_previous(cursor, identifier) + feature['next'] = self.get_next(cursor, identifier) return feature def __response_feature(self, row_data): diff --git a/pygeoapi/templates/item.html b/pygeoapi/templates/item.html index 5b5b171..037a4ec 100644 --- a/pygeoapi/templates/item.html +++ b/pygeoapi/templates/item.html @@ -37,7 +37,28 @@