GeoserverConfig.Datastores (GeoserverConfig v0.4.1)

Copy Markdown View Source

Provides functions to manage GeoServer datastores via its REST API.

Supports listing, creating, updating, and deleting datastores within a specific GeoServer workspace. All functions require a GeoserverConfig.Connection as their first argument.

Supported datastore types

  • "postgis" — PostgreSQL/PostGIS
  • "geopkg" — GeoPackage file
  • "shapefile" — Shapefile
  • "wfs" — Web Feature Service

Summary

Functions

Creates a new datastore in the specified workspace.

Deletes a datastore from the given workspace.

Fetches a single datastore by name from the given workspace.

Lists all datastores in the given workspace.

Resets the caches related to this specific data store.

Uploads files to a data store, creating it if necessary.

Functions

create_datastore(conn, workspace, name, type, connection_params)

Creates a new datastore in the specified workspace.

Returns

  • {:ok, name} on success
  • {:error, reason} on failure

delete_datastore(conn, workspace, datastore_name, recurse \\ false)

Deletes a datastore from the given workspace.

Returns

  • {:ok, datastore_name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, message}} on transport error

get_datastore(conn, workspace, datastore_name, opts \\ [])

Fetches a single datastore by name from the given workspace.

Options

  • :quiet_on_not_found — when true, avoids logging an exception on 404 (default: false)

Returns

  • {:ok, datastore} on success (a map with datastore details)
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, exception} on transport error

list_datastores(conn, workspace)

Lists all datastores in the given workspace.

GeoServer returns a single map when there is only one datastore; this function normalises that to always return a list.

Returns

  • {:ok, [datastore]} on success
  • {:error, {:http_error, status, body}} on non-200 response
  • {:error, exception} on transport error

reset_datastore(conn, workspace, datastore_name)

Resets the caches related to this specific data store.

This forces GeoServer to drop cached data store structures and reconnect to the vector source the next time it is needed.

Returns

  • {:ok, datastore_name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error

update_datastore(conn, workspace, datastore_name, datastore_type, connection_params)

Updates an existing datastore's configuration.

Returns

  • {:ok, datastore_name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, message}} on transport error

upload_datastore(conn, workspace, store_name, method, format, body, opts \\ [])

Uploads files to a data store, creating it if necessary.

Uses the PUT /datastores/{store}/{method}.{format} endpoint.

Parameters

  • conn — a GeoserverConfig.Connection
  • workspace — the workspace name
  • store_name — target datastore name (will be created if absent)
  • method:file, :url, or :external
  • format — the file extension (e.g. "shp", "geopkg", "properties")
  • body — file content (for :file), a URL string (for :url), or a local path (for :external)
  • opts — optional keyword list:
    • :configure"none", "first" (default), or "all"
    • :target — target data store format (e.g. "shp")
    • :update"append" (default) or "overwrite"
    • :charset — character encoding (e.g. "ISO-8859-1")
    • :filename — target filename for the uploaded file
    • :content_type — override Content-Type header

Returns

  • {:ok, store_name} on success
  • {:error, {:http_error, status, body}} on failure
  • {:error, {:request_failed, reason}} on transport error