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