Mercurial > gemma
view pkg/controllers/search.go @ 4605:7650d2431f86 geoserver_sql_views
Separate schema and table name
Since a GeoServer data source is bound to a specific database schema,
names have to be given without schema qualification. Since we cannot
use regclass for names of SQL views, the name is now a varchar. This
way it's more straightforward to store schema and name separately.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 05 Sep 2019 11:33:01 +0200 |
parents | 4394daeea96a |
children | e020e6e34ad7 |
line wrap: on
line source
// This is Free Software under GNU Affero General Public License v >= 3.0 // without warranty, see README.md and license for details. // // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // // Copyright (C) 2018 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha Wilde <sascha.wilde@intevation.de> // * Sascha Teichmann <sascha.teichmann@intevation.de> package controllers import ( "database/sql" "net/http" "strings" "gemma.intevation.de/gemma/pkg/models" mw "gemma.intevation.de/gemma/pkg/middleware" ) const ( searchMostSQL = `SELECT search_most($1)::text` listBottlenecksSQL = ` SELECT COALESCE(json_agg(r),'[]') FROM ( SELECT objnam AS name, ST_AsGeoJSON(ST_Centroid(area))::json AS geom, 'bottleneck' AS type FROM waterway.bottlenecks WHERE validity @> current_timestamp ORDER BY objnam) r ` ) func searchFeature(req *http.Request) (jr mw.JSONResult, err error) { s := mw.JSONInput(req).(*models.SearchRequest) if len(s.SearchString) == 0 { err = mw.JSONError{http.StatusBadRequest, "error: empty search string"} return } var result string err = mw.JSONConn(req).QueryRowContext( req.Context(), searchMostSQL, s.SearchString, ).Scan(&result) if err != nil { return } jr.Result = strings.NewReader(result) return } func listBottlenecks(req *http.Request) (jr mw.JSONResult, err error) { var result string err = mw.JSONConn(req).QueryRowContext( req.Context(), listBottlenecksSQL).Scan(&result) switch { case err == sql.ErrNoRows: err = mw.JSONError{ Code: http.StatusNotFound, Message: "Cannot find any bottleneck.", } return case err != nil: return } jr = mw.JSONResult{Result: strings.NewReader(result)} return }