Skip to content

Commit

Permalink
feat: #21 support functions with nullable parameters and return type
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-m committed Jan 7, 2024
1 parent 6963847 commit 6d4775f
Show file tree
Hide file tree
Showing 7 changed files with 972 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
Cargo.lock
/.idea
/.vscode
*.iml
/prof
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "postgis_diesel"
version = "2.2.2"
version = "2.3.0"
authors = ["Vitaly Merenkov <[email protected]>"]
edition = "2018"
description = "An extension for Diesel framework to support PostGIS geometry datatype."
Expand Down
121 changes: 121 additions & 0 deletions src/functions_nullable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use crate::sql_types::*;
use diesel::sql_types::*;

//Topological Relationships****************************************************************

sql_function! {
/// Tests if two geometries spatially intersect in 3D - only for points, linestrings, polygons, polyhedral surface (area).
#[sql_name="ST_3DIntersects"]
fn st_3d_intersects(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if no points of B lie in the exterior of A, and A and B have at least one interior point in common.
#[sql_name="ST_Contains"]
fn st_contains(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if B intersects the interior of A but not the boundary or exterior.
#[sql_name="ST_ContainsProperly"]
fn st_contains_properly(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if no point in A is outside B
#[sql_name="ST_CoveredBy"]
fn st_covered_by<G: GeoType>(left: Nullable<G>, right: Nullable<G>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if no point in B is outside A
#[sql_name="ST_Covers"]
fn st_covers<G: GeoType>(left: Nullable<G>, right: Nullable<G>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries have some, but not all, interior points in common.
#[sql_name="ST_Crosses"]
fn st_crosses(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries are disjoint (they have no point in common).
#[sql_name="ST_Disjoint"]
fn st_disjoint(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries include the same set of points.
#[sql_name="ST_Equals"]
fn st_equals(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries intersect (they have at least one point in common).
#[sql_name="ST_Intersects"]
fn st_intersects<G: GeoType>(left: Nullable<G>, right: Nullable<G>) -> Nullable<Bool>;
}
sql_function! {
/// Returns a number indicating the crossing behavior of two LineStrings.
#[sql_name="ST_LineCrossingDirection"]
fn st_line_crossing_direction(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Integer>;
}
sql_function! {
/// Tests if two geometries represent the same Nullable<Geometry> and have points in the same directional order.
#[sql_name="ST_OrderingEquals"]
fn st_ordering_equals(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries intersect and have the same dimension, but are not completely contained by each other.
#[sql_name="ST_Overlaps"]
fn st_overlaps(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries have a topological relationship matching an Intersection Matrix pattern.
#[sql_name="ST_Relate"]
fn st_relate_check(left: Nullable<Geometry>, right: Nullable<Geometry>, intersection_matrix_mattern: Nullable<Text>) -> Nullable<Bool>;
}
sql_function! {
/// Computes Intersection Matrix of two geometries.
#[sql_name="ST_Relate"]
fn st_relate(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Text>;
}
sql_function! {
/// Computes Intersection Matrix of two geometries. The boundary node rule code is: 1: OGC/MOD2, 2: Endpoint, 3: MultivalentEndpoint, 4: MonovalentEndpoint.
#[sql_name="ST_Relate"]
fn st_relate_bnr(left: Nullable<Geometry>, right: Nullable<Geometry>, boundary_node_rule: Nullable<Integer>) -> Nullable<Text>;
}
sql_function! {
/// Tests if a DE-9IM Intersection Matrix matches an Intersection Matrix pattern
#[sql_name="ST_RelateMatch"]
fn st_relate_match(intersection_matrix: Nullable<Text>, intersection_matrix_pattern: Nullable<Text>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if two geometries have at least one point in common, but their interiors do not intersect.
#[sql_name="ST_Touches"]
fn st_touches(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if no points of A lie in the exterior of B, and A and B have at least one interior point in common.
#[sql_name="ST_Within"]
fn st_within(left: Nullable<Geometry>, right: Nullable<Geometry>) -> Nullable<Bool>;
}
sql_function! {
/// Tests if A and B are within a given distance.
#[sql_name="ST_DWithin"]
fn st_d_within<G: GeoType>(left: Nullable<G>, right: Nullable<G>, distance: Nullable<Double>) -> Nullable<Bool>;
}

pub type St3DIntersects<GeomA, GeomB> = st_3d_intersects::HelperType<GeomA, GeomB>;
pub type StContains<GeomA, GeomB> = st_contains::HelperType<GeomA, GeomB>;
pub type StContainsProperly<GeomA, GeomB> = st_contains_properly::HelperType<GeomA, GeomB>;
pub type StCoveredBy<G, GeomA, GeomB> = st_covered_by::HelperType<G, GeomA, GeomB>;
pub type StCovers<G, GeomA, GeomB> = st_covers::HelperType<G, GeomA, GeomB>;
pub type StCrosses<GeomA, GeomB> = st_crosses::HelperType<GeomA, GeomB>;
pub type StDisjoint<GeomA, GeomB> = st_disjoint::HelperType<GeomA, GeomB>;
pub type StEquals<GeomA, GeomB> = st_equals::HelperType<GeomA, GeomB>;
pub type StIntersects<G, GeomA, GeomB> = st_intersects::HelperType<G, GeomA, GeomB>;
pub type StLineCrossingDirection<GeomA, GeomB> =
st_line_crossing_direction::HelperType<GeomA, GeomB>;
pub type StOrderingEquals<GeomA, GeomB> = st_ordering_equals::HelperType<GeomA, GeomB>;
pub type StOverlaps<GeomA, GeomB> = st_overlaps::HelperType<GeomA, GeomB>;
pub type StRelateCheck<GeomA, GeomB, Matrix> = st_relate_check::HelperType<GeomA, GeomB, Matrix>;
pub type StRelate<GeomA, GeomB> = st_relate::HelperType<GeomA, GeomB>;
pub type StRelateBnr<GeomA, GeomB, BNRule> = st_relate_bnr::HelperType<GeomA, GeomB, BNRule>;
pub type StRelateMatch<GeomA, GeomB> = st_relate_match::HelperType<GeomA, GeomB>;
pub type StTouches<GeomA, GeomB> = st_touches::HelperType<GeomA, GeomB>;
pub type StWithin<GeomA, GeomB> = st_within::HelperType<GeomA, GeomB>;
pub type StDWithin<G, GeomA, GeomB, Distance> = st_d_within::HelperType<G, GeomA, GeomB, Distance>;
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate serde;

mod ewkb;
pub mod functions;
pub mod functions_nullable;
#[cfg(feature = "serde_geojson")]
mod geojson;
mod geometrycollection;
Expand Down
9 changes: 0 additions & 9 deletions src/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ diesel::infix_operator!(Distance2BBs, " <#> ", diesel::sql_types::Double);
diesel::infix_operator!(DistanceNdCentroidsBBs, " <<->> ", diesel::sql_types::Double);
diesel::infix_operator!(DistanceNdBBs, " <<#>> ", diesel::sql_types::Double);

sql_function! {
/// ST_Intersects returns TRUE if the intersection of the geometries or geographies is non-empty.
///
/// It is much faster than computing said intersection.
#[deprecated(since = "2.1.0", note = "please use functions::st_intersects instead, it will be removed in 2.2.0")]
fn st_intersects(left: Geography, right: Geography) -> Bool;
}
pub type StIntersects<ExprLeft, ExprRight> = st_intersects::HelperType<ExprLeft, ExprRight>;

/// The @ operator returns TRUE if the bounding box of geometry A is completely contained by the bounding box of geometry B.
pub fn contained_by<T, U>(left: T, right: U) -> BBContainedBy<T, U::Expression>
where
Expand Down
Loading

0 comments on commit 6d4775f

Please sign in to comment.