@pgpm/geotypes 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -2,4 +2,229 @@
|
|
|
2
2
|
|
|
3
3
|
Geographic data types and spatial functions for PostgreSQL.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@pgpm/geotypes` provides PostgreSQL domain types for geographic data, built on top of PostGIS geometry types. This package enables type-safe storage and validation of geographic coordinates and polygons with proper SRID (Spatial Reference System Identifier) enforcement.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **geolocation**: A domain type for geographic points (latitude/longitude) using WGS84 (SRID 4326)
|
|
12
|
+
- **geopolygon**: A domain type for geographic polygons using WGS84 (SRID 4326)
|
|
13
|
+
- Automatic SRID validation to ensure coordinate system consistency
|
|
14
|
+
- Integration with PostGIS spatial functions
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
If you have `pgpm` installed:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pgpm install @pgpm/geotypes
|
|
22
|
+
pgpm deploy
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This is a quick way to get started. The sections below provide more detailed installation options.
|
|
26
|
+
|
|
27
|
+
### Prerequisites
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install pgpm globally
|
|
31
|
+
npm install -g pgpm
|
|
32
|
+
|
|
33
|
+
# Start PostgreSQL
|
|
34
|
+
pgpm docker start
|
|
35
|
+
|
|
36
|
+
# Set environment variables
|
|
37
|
+
eval "$(pgpm env)"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Deploy
|
|
41
|
+
|
|
42
|
+
#### Option 1: Deploy by installing with pgpm
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pgpm install @pgpm/geotypes
|
|
46
|
+
pgpm deploy
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Option 2: Deploy from Package Directory
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cd packages/data-types/geotypes
|
|
53
|
+
pgpm deploy --createdb
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Option 3: Deploy from Workspace Root
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Install workspace dependencies
|
|
60
|
+
pgpm install
|
|
61
|
+
|
|
62
|
+
# Deploy with dependencies
|
|
63
|
+
pgpm deploy mydb1 --yes --createdb
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
### Creating Tables with Geographic Types
|
|
69
|
+
|
|
70
|
+
```sql
|
|
71
|
+
CREATE TABLE places (
|
|
72
|
+
id serial PRIMARY KEY,
|
|
73
|
+
loc geolocation,
|
|
74
|
+
area geopolygon
|
|
75
|
+
);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Inserting Geographic Data
|
|
79
|
+
|
|
80
|
+
```sql
|
|
81
|
+
-- Insert a point location (San Francisco)
|
|
82
|
+
INSERT INTO places (loc)
|
|
83
|
+
VALUES (
|
|
84
|
+
ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 4326)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
-- Insert a polygon area
|
|
88
|
+
INSERT INTO places (area)
|
|
89
|
+
VALUES (
|
|
90
|
+
ST_SetSRID(
|
|
91
|
+
ST_GeomFromText('POLYGON((-122.5 37.7, -122.4 37.7, -122.4 37.8, -122.5 37.8, -122.5 37.7))'),
|
|
92
|
+
4326
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### SRID Validation
|
|
98
|
+
|
|
99
|
+
The domain types automatically enforce SRID 4326 (WGS84):
|
|
100
|
+
|
|
101
|
+
```sql
|
|
102
|
+
-- This will fail - incorrect SRID
|
|
103
|
+
INSERT INTO places (loc)
|
|
104
|
+
VALUES (
|
|
105
|
+
ST_SetSRID(ST_MakePoint(-122.4194, 37.7749), 3857)
|
|
106
|
+
);
|
|
107
|
+
-- ERROR: value for domain geolocation violates check constraint
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Domain Types
|
|
111
|
+
|
|
112
|
+
### geolocation
|
|
113
|
+
|
|
114
|
+
A PostgreSQL domain based on `geometry(Point, 4326)` that stores geographic point coordinates.
|
|
115
|
+
|
|
116
|
+
- **Base Type**: `geometry(Point, 4326)`
|
|
117
|
+
- **Use Case**: Storing latitude/longitude coordinates for locations
|
|
118
|
+
- **SRID**: 4326 (WGS84 - World Geodetic System 1984)
|
|
119
|
+
|
|
120
|
+
### geopolygon
|
|
121
|
+
|
|
122
|
+
A PostgreSQL domain based on `geometry(Polygon, 4326)` that stores geographic polygon areas.
|
|
123
|
+
|
|
124
|
+
- **Base Type**: `geometry(Polygon, 4326)`
|
|
125
|
+
- **Use Case**: Storing geographic boundaries, regions, or areas
|
|
126
|
+
- **SRID**: 4326 (WGS84)
|
|
127
|
+
- **Validation**: Ensures valid polygon geometry (closed rings, proper vertex count)
|
|
128
|
+
|
|
129
|
+
## Dependencies
|
|
130
|
+
|
|
131
|
+
- `@pgpm/types`: Core PostgreSQL type definitions
|
|
132
|
+
- `@pgpm/verify`: Verification utilities for database objects
|
|
133
|
+
- PostGIS extension (required for geometry types)
|
|
134
|
+
|
|
135
|
+
## Testing
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
pnpm test
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The test suite validates:
|
|
142
|
+
- Successful insertion of valid points and polygons
|
|
143
|
+
- SRID validation and rejection of incorrect coordinate systems
|
|
144
|
+
- Polygon geometry validation
|
|
145
|
+
|
|
146
|
+
## Development
|
|
147
|
+
|
|
148
|
+
See the [Development](#development) section below for information on working with this package.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Development
|
|
153
|
+
|
|
154
|
+
### **Before You Begin**
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# 1. Install pgpm
|
|
158
|
+
npm install -g pgpm
|
|
159
|
+
|
|
160
|
+
# 2. Start Postgres (Docker or local)
|
|
161
|
+
pgpm docker start
|
|
162
|
+
|
|
163
|
+
# 3. Load PG* environment variables (PGHOST, PGUSER, ...)
|
|
164
|
+
eval "$(pgpm env)"
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### **Starting a New Project**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# 1. Create a workspace
|
|
173
|
+
pgpm init --workspace
|
|
174
|
+
cd my-app
|
|
175
|
+
|
|
176
|
+
# 2. Create your first module
|
|
177
|
+
pgpm init
|
|
178
|
+
|
|
179
|
+
# 3. Add a migration
|
|
180
|
+
pgpm add some_change
|
|
181
|
+
|
|
182
|
+
# 4. Deploy (auto-creates database)
|
|
183
|
+
pgpm deploy --createdb
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
### **Working With an Existing Project**
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# 1. Clone and enter the project
|
|
192
|
+
git clone <repo> && cd <project>
|
|
193
|
+
|
|
194
|
+
# 2. Install dependencies
|
|
195
|
+
pnpm install
|
|
196
|
+
|
|
197
|
+
# 3. Deploy locally
|
|
198
|
+
pgpm deploy --createdb
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### **Testing a Module Inside a Workspace**
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# 1. Install workspace deps
|
|
207
|
+
pnpm install
|
|
208
|
+
|
|
209
|
+
# 2. Enter the module directory
|
|
210
|
+
cd packages/<some-module>
|
|
211
|
+
|
|
212
|
+
# 3. Run tests in watch mode
|
|
213
|
+
pnpm test:watch
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Related Tooling
|
|
217
|
+
|
|
218
|
+
* [pgpm](https://github.com/launchql/launchql/tree/main/packages/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
219
|
+
* [pgsql-test](https://github.com/launchql/launchql/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
220
|
+
* [supabase-test](https://github.com/launchql/launchql/tree/main/packages/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
221
|
+
* [graphile-test](https://github.com/launchql/launchql/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
222
|
+
* [pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
223
|
+
* [libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
224
|
+
* [pg-proto-parser](https://github.com/launchql/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
225
|
+
|
|
226
|
+
## Disclaimer
|
|
227
|
+
|
|
228
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
229
|
+
|
|
230
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# launchql-geo-types extension
|
|
2
2
|
comment = 'launchql-geo-types extension'
|
|
3
|
-
default_version = '0.4.
|
|
3
|
+
default_version = '0.4.0'
|
|
4
4
|
module_pathname = '$libdir/launchql-geo-types'
|
|
5
5
|
requires = 'plpgsql,citext,postgis,launchql-types,launchql-verify'
|
|
6
6
|
relocatable = false
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/geotypes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Geographic data types and spatial functions for PostgreSQL",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"bundle": "
|
|
9
|
+
"bundle": "pgpm package",
|
|
10
10
|
"test": "jest",
|
|
11
11
|
"test:watch": "jest --watch"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@pgpm/types": "0.
|
|
15
|
-
"@pgpm/verify": "0.
|
|
14
|
+
"@pgpm/types": "0.5.0",
|
|
15
|
+
"@pgpm/verify": "0.5.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"
|
|
18
|
+
"pgpm": "^0.2.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/launchql/extensions/issues"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "d8eedbb24ad22a106634bc3b919bfb8d41976c16"
|
|
29
29
|
}
|
|
File without changes
|
|
File without changes
|