Skip to content

Commit

Permalink
feat: add pgstac
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Apr 27, 2024
1 parent 538b54c commit f722391
Show file tree
Hide file tree
Showing 13 changed files with 1,111 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ jobs:
sudo apt-get install libgdal-dev
- name: Test
run: cargo test -p stac -p stac-cli # gdal is default for stac-cli
test-ubuntu-with-pgstac:
runs-on: ubuntu-latest
services:
pgstac:
image: ghcr.io/stac-utils/pgstac:v0.8.5
env:
POSTGRES_USER: username
POSTGRES_PASSWORD: password
POSTGRES_DB: postgis
PGUSER: username
PGPASSWORD: password
PGDATABASE: postgis
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Rust cache
uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test -p pgstac
test-windows:
runs-on: windows-latest
steps:
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
[workspace]
resolver = "2"
members = [
"stac",
"pgstac",
"stac-api",
"stac-async",
"stac-cli",
"stac-validate",
]
default-members = [
"stac",
"stac-api",
"stac-async",
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ See [RELEASING.md](./RELEASING.md) for a checklist to use when releasing a new v

Here's some related projects that use this repo:

- [pgstac-rs](https://github.com/stac-utils/pgstac-rs): Rust interface for [pgstac](https://github.com/stac-utils/pgstac), PostgreSQL schema and functions for STAC
- [stac-server-rs](https://github.com/gadomski/stac-server-rs): A STAC API server implementation

## License
Expand Down
49 changes: 49 additions & 0 deletions pgstac/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.0.6] - 2024-04-20

- Bump **stac** version to v0.6
- Bump **pgstac** version to v0.8.5

## [0.0.5] - 2023-09-25

- Bump **stac-api** version to v0.3.0

## [0.0.4] - 2023-07-07

- Bump **stac** version to v0.5
- Bump **pgstac** version to v0.6.13 ([#2](https://github.com/stac-utils/pgstac-rs/pull/2))

## [0.0.3] - 2023-01-08

### Changed

- `Client` now takes a reference to a generic client, instead of owning it

### Removed

- `Client::into_inner`

## [0.0.2] - 2023-01-08

### Changed

- Make `Error`, `Result`, and `Context` publicly visible

## [0.0.1] - 2023-01-07

Initial release

[unreleased]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.6...HEAD
[0.0.6]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.5...v0.0.6
[0.0.5]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/stac-utils/pgstac-rs/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/stac-utils/pgstac-rs/tree/v0.0.1
25 changes: 25 additions & 0 deletions pgstac/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "pgstac"
version = "0.0.6"
authors = ["Pete Gadomski <[email protected]>"]
edition = "2021"
description = "Rust interface for pgstac"
homepage = "https://github.com/stac-utils/stac-rs"
repository = "https://github.com/stac-utils/stac-rs"
license = "MIT OR Apache-2.0"
keywords = ["geospatial", "stac", "metadata", "raster", "database"]
categories = ["database", "data-structures", "science"]

[dependencies]
geojson = "0.24"
serde = "1"
serde_json = "1"
stac = { version = "0.6", path = "../stac" }
stac-api = { version = "0.3", path = "../stac-api" }
thiserror = "1"
tokio-postgres = { version = "0.7", features = ["with-serde_json-1"] }

[dev-dependencies]
pgstac-test = { path = "pgstac-test" }
tokio = { version = "1.23", features = ["rt-multi-thread", "macros"] }
tokio-test = "0.4"
45 changes: 45 additions & 0 deletions pgstac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# pgstac

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/stac-utils/stac-rs/ci.yml?branch=main&style=for-the-badge)](https://github.com/stac-utils/stac-rs/actions/workflows/ci.yml)
[![docs.rs](https://img.shields.io/docsrs/pgstac?style=for-the-badge)](https://docs.rs/pgstac/latest/pgstac/)
[![Crates.io](https://img.shields.io/crates/v/pgstac?style=for-the-badge)](https://crates.io/crates/pgstac)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg?style=for-the-badge)](./CODE_OF_CONDUCT)

Rust interface for [pgstac](https://github.com/stac-utils/pgstac).

## Usage

In your `Cargo.toml`:

```toml
[dependencies]
pgstac = "0.0.6"
```

See the [documentation](https://docs.rs/pgstac) for more.

## Testing

**pgstac** needs a blank **pgstac** database for testing, so is not part of the default workspace build.
To test:

```shell
docker-compose -f pgstac/docker-compose.yml up -d
cargo test -p pgstac
docker-compose -f pgstac/docker-compose.yml down
```

Each test is run in its own transaction, which is rolled back after the test.

### Customizing the test database connection

By default, the tests will connect to the database at `postgresql://username:password@localhost:5432/postgis`.
If you need to customize the connection information for whatever reason, set your `PGSTAC_RS_TEST_DB` environment variable:

```shell
PGSTAC_RS_TEST_DB=postgresql://otherusername:otherpassword@otherhost:7822/otherdbname cargo test
```

## Other info

This crate is part of the [stac-rs](https://github.com/stac-utils/stac-rs) monorepo, see its README for contributing and license information.
14 changes: 14 additions & 0 deletions pgstac/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
database:
container_name: stac-rs
image: ghcr.io/stac-utils/pgstac:v0.8.5
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgis
- PGUSER=username
- PGPASSWORD=password
- PGDATABASE=postgis
ports:
- "5432:5432"
command: postgres -N 500
1 change: 1 addition & 0 deletions pgstac/pgstac-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
15 changes: 15 additions & 0 deletions pgstac/pgstac-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "pgstac-test"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
proc-macro = true
test = false
doctest = false

[dependencies]
quote = "1"
syn = { version = "2", features = ["full", "extra-traits"] }
tokio-postgres = { version = "0.7" }
31 changes: 31 additions & 0 deletions pgstac/pgstac-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::ItemFn;

#[proc_macro_attribute]
pub fn pgstac_test(_args: TokenStream, input: TokenStream) -> TokenStream {
let ast = syn::parse(input).unwrap();
impl_pgstac_test(ast)
}

fn impl_pgstac_test(ast: ItemFn) -> TokenStream {
let ident = &ast.sig.ident;
let gen = quote! {
#[tokio::test]
async fn #ident() {
let _mutex = MUTEX.lock().unwrap();
let config = std::env::var("PGSTAC_RS_TEST_DB")
.unwrap_or("postgresql://username:password@localhost:5432/postgis".to_string());
let (mut client, connection) = tokio_postgres::connect(&config, tokio_postgres::NoTls).await.unwrap();
tokio::spawn(async move {
connection.await.unwrap()
});
let transaction = client.transaction().await.unwrap();
let client = Client::new(&transaction);
#ast
#ident(&client).await;
transaction.rollback().await.unwrap();
}
};
gen.into()
}
Loading

0 comments on commit f722391

Please sign in to comment.