1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! GeoPackage reader/writer built on top of rusqlite.
//!
//! ## Overview
//!
//! The crate supports two GeoPackage content types:
//!
//! **Feature layers** (spatial data with geometry):
//! - [`Gpkg`] -- the GeoPackage connection.
//! - [`GpkgLayer`] -- a single feature layer (table with geometry column).
//! - [`GpkgFeature`] -- a single feature (row with geometry + properties).
//!
//! **Attribute tables** (non-spatial tabular data, no geometry):
//! - [`GpkgAttributeTable`] -- a single attribute table.
//! - [`GpkgAttributeRow`] -- a single row (properties only, no geometry).
//!
//! [`Value`] represents a single property value in both cases.
//!
//! Apache Arrow support is available behind the `arrow` feature flag.
//!
//! `Gpkg` is the entry point and supports several open modes:
//! `Gpkg::open_read_only(path)`, `Gpkg::open(path)`, and `Gpkg::open_in_memory()`.
//!
//! `GpkgLayer::features()` loads all features into memory. For large datasets,
//! use `features_batch(batch_size)` to stream in chunks.
//!
//! `GpkgLayer::insert` and `GpkgLayer::update` accept any geometry that implements
//! `geo_traits::GeometryTrait<T = f64>` (for example `geo_types::Point`).
//!
//! ## Browser usage
//!
//! On wasm targets, you can open with a custom writer (for example an OPFS-backed
//! writer wrapper) via `open_with_writer()`:
//!
//! ```no_run
//! # #[cfg(target_family = "wasm")]
//! use rusqlite_gpkg::Gpkg;
//! # #[cfg(target_family = "wasm")]
//! # fn open_from_opfs<W: std::io::Write + std::io::Seek + 'static>(opfs_writer: W) -> Result<(), rusqlite_gpkg::GpkgError> {
//! let _gpkg = Gpkg::open_with_writer("demo.sqlite", opfs_writer)?;
//! # Ok(())
//! # }
//! ```
//!
//! If you prefer a storage-agnostic flow, use `to_bytes()` / `from_bytes()`:
//!
//! ```no_run
//! use rusqlite_gpkg::Gpkg;
//! let gpkg = Gpkg::open_in_memory()?;
//! let bytes = gpkg.to_bytes()?;
//! let _restored = Gpkg::from_bytes(&bytes)?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## Gpkg
//!
//! `Gpkg` represents the GeoPackage connection and is the entry point for
//! opening databases, listing layers, and creating new layers.
//!
//! - `list_layers()` / `get_layer(name)` / `create_layer(...)` for feature layers.
//! - `list_attribute_tables()` / `get_attribute_table(name)` / `create_attribute_table(...)` for attribute tables.
//!
//! ```no_run
//! use rusqlite_gpkg::Gpkg;
//! let gpkg = Gpkg::open_read_only("data/example.gpkg")?;
//! let layer = gpkg.get_layer("points")?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## GpkgLayer
//!
//! `GpkgLayer` models a single feature table. It exposes schema information
//! (geometry column, property columns) and provides read/write operations.
//!
//! ```no_run
//! use geo_types::Point;
//! use rusqlite_gpkg::{Gpkg, params};
//! let layer = Gpkg::open("data.gpkg")?.get_layer("points")?;
//! layer.insert(Point::new(1.0, 2.0), params!["alpha", 7_i64])?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## GpkgFeature
//!
//! `GpkgFeature` represents one row. You can read the primary key, geometry, and
//! property values from it.
//!
//! ```no_run
//! use rusqlite_gpkg::Gpkg;
//! let features = Gpkg::open_read_only("data.gpkg")?
//! .get_layer("points")?
//! .features()?;
//! let feature = features.first().expect("feature");
//! let _geom = feature.geometry()?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## Value
//!
//! `Value` is the crate's owned dynamic value for feature properties, mirroring
//! SQLite's dynamic typing. Convert with `try_into()` or match directly.
//!
//! ```no_run
//! use rusqlite_gpkg::Gpkg;
//! let features = Gpkg::open_read_only("data.gpkg")?
//! .get_layer("points")?
//! .features()?;
//! let feature = features.first().expect("feature");
//! let name: String = feature
//! .property("name")
//! .ok_or_else(|| rusqlite_gpkg::GpkgError::MissingProperty {
//! property: "name".to_string(),
//! })?
//! .try_into()?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## Attribute tables
//!
//! Attribute tables hold non-spatial data (no geometry column). They follow
//! the GeoPackage spec Section 2.4 (`data_type = 'attributes'` in `gpkg_contents`).
//!
//! ```no_run
//! use rusqlite_gpkg::{ColumnSpec, ColumnType, Gpkg, params};
//! let gpkg = Gpkg::open_in_memory()?;
//! let columns = vec![
//! ColumnSpec { name: "name".to_string(), column_type: ColumnType::Varchar },
//! ColumnSpec { name: "value".to_string(), column_type: ColumnType::Integer },
//! ];
//! let table = gpkg.create_attribute_table("observations", &columns)?;
//! table.insert(params!["alpha", 7_i64])?;
//!
//! let rows = table.rows()?;
//! let name: String = rows[0].property("name").unwrap().try_into()?;
//! # Ok::<(), rusqlite_gpkg::GpkgError>(())
//! ```
//!
//! ## Arrow (feature = "arrow")
//!
//! The Arrow reader yields `RecordBatch`es for a layer. It borrows the `Gpkg`
//! because it holds a prepared statement internally.
//!
//! ```no_run
//! # #[cfg(feature = "arrow")]
//! use rusqlite_gpkg::{ArrowGpkgReader, Gpkg};
//! # #[cfg(feature = "arrow")]
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let gpkg = Gpkg::open_read_only("data/example.gpkg")?;
//! let mut reader = ArrowGpkgReader::new(&gpkg, "points", 256)?;
//! let _batch = reader.next().transpose()?;
//! Ok(())
//! }
//! # #[cfg(not(feature = "arrow"))]
//! fn main() {}
//! ```
pub use ArrowGpkgAttributeReader;
pub use ArrowGpkgAttributeWriter;
pub use ArrowGpkgReader;
pub use ArrowGpkgWriter;
pub use ;
pub use ;
pub use register_spatial_functions;
pub use ;
// Re-export types used in public fields to keep the public API stable.
pub use ;
pub use ;