Skip to main content

ogc_cql2/ds/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2
3#![warn(missing_docs)]
4
5//! Groups artifacts providing Features and Resources from known types used in
6//! the geospatial ecosystem such as CSV, and GeoPackage files.
7//!
8
9#[cfg(feature = "csv_ds")]
10mod csv;
11#[cfg(feature = "gpkg_ds")]
12mod gpkg;
13#[cfg(feature = "pg_ds")]
14mod pg;
15#[cfg(any(feature = "gpkg_ds", feature = "pg_ds"))]
16mod sql;
17#[cfg(feature = "pg_ds")]
18mod types;
19
20#[cfg(feature = "csv_ds")]
21pub use csv::*;
22#[cfg(feature = "gpkg_ds")]
23pub use gpkg::*;
24#[cfg(feature = "pg_ds")]
25pub use pg::*;
26#[cfg(feature = "pg_ds")]
27pub use types::*;
28
29use crate::{Expression, Q};
30use async_trait::async_trait;
31use futures::stream::BoxStream;
32use std::collections::HashMap;
33
34/// A dictionary of queryable property names (strings) to [`Queryable`][Q] values.
35pub type Resource = HashMap<String, Q>;
36
37/// Trait for a type that can act as a data source provider of _Features_
38/// and [`Resource`]s, including a _Geometry_ attribute, in the context of
39/// processing CQL2 filter expressions.
40///
41/// A CSV file, and a GeoPackage autonomous database file are examples of this.
42pub trait DataSource {
43    /// Return SRID of this if it was known at construction; `None` otherwise.
44    fn srid(&self) -> Option<u32>;
45}
46
47/// Capability of a [`DataSource`] to provide an iterator over a collection of
48/// _Features_ or [Resources][Resource].
49pub trait IterableDS {
50    /// Type representing a Feature which must be convertible to a [Resource].
51    type Item: TryInto<Resource, Error = Self::Err>;
52    /// Error raised by this.
53    type Err;
54
55    /// Return an iterator over this data source _Features_.
56    fn iter(&self) -> Result<impl Iterator<Item = Result<Self::Item, Self::Err>>, Self::Err>;
57}
58
59/// Capability of a [`DataSource`] to asynchronously stream _Features_ or
60/// [Resources][Resource].
61#[async_trait]
62pub trait StreamableDS {
63    /// Type representing a _Feature_ which must be convertible to a [`Resource`].
64    type Item: TryInto<Resource, Error = Self::Err>;
65    /// Error raised by this.
66    type Err;
67
68    /// Return an unfiltered stream of all data source _Features_.
69    async fn fetch(&self) -> Result<BoxStream<'_, Result<Self::Item, Self::Err>>, Self::Err>;
70
71    /// Return an unfiltered stream of all data source _Resources_.
72    async fn stream(&self) -> Result<BoxStream<'_, Result<Resource, Self::Err>>, Self::Err>;
73
74    /// Return a filtered stream of _Features_ satisfying a CQL2 filter [Expression].
75    async fn fetch_where(
76        &self,
77        exp: &Expression,
78    ) -> Result<BoxStream<'_, Result<Self::Item, Self::Err>>, Self::Err>;
79
80    /// Return a filtered stream of _Resources_ satisfying a CQL2 filter [Expression].
81    async fn stream_where(
82        &self,
83        exp: &Expression,
84    ) -> Result<BoxStream<'_, Result<Resource, Self::Err>>, Self::Err>;
85}