@pgpm/measurements 0.4.0 → 0.6.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,259 @@
|
|
|
2
2
|
|
|
3
3
|
Measurement utilities for performance tracking and analytics.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@pgpm/measurements` provides a standardized system for tracking measurements and quantities in PostgreSQL applications. This package defines a schema for storing measurement types with their units and descriptions, enabling consistent metric tracking across your application.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Quantity Definitions**: Store measurement types with units and descriptions
|
|
12
|
+
- **Standardized Units**: Define consistent units across your application
|
|
13
|
+
- **Fixture Data**: Pre-populated common measurement types
|
|
14
|
+
- **Extensible Schema**: Easy to add custom measurement types
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
If you have `pgpm` installed:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pgpm install @pgpm/measurements
|
|
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/measurements
|
|
46
|
+
pgpm deploy
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Option 2: Deploy from Package Directory
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
cd packages/metrics/measurements
|
|
53
|
+
pgpm deploy --createdb
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### Option 3: Deploy from Workspace Root
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Install workspace dependencies
|
|
60
|
+
pnpm install
|
|
61
|
+
|
|
62
|
+
# Deploy with dependencies
|
|
63
|
+
pgpm deploy mydb1 --yes --createdb
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Core Schema
|
|
67
|
+
|
|
68
|
+
### measurements.quantities Table
|
|
69
|
+
|
|
70
|
+
Stores measurement type definitions:
|
|
71
|
+
- `id`: Serial primary key
|
|
72
|
+
- `name`: Measurement identifier (e.g., 'distance', 'weight', 'temperature')
|
|
73
|
+
- `label`: Display label
|
|
74
|
+
- `unit`: Unit of measurement (e.g., 'meters', 'kilograms', 'celsius')
|
|
75
|
+
- `unit_desc`: Unit description
|
|
76
|
+
- `description`: Measurement description
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
### Defining Measurement Types
|
|
81
|
+
|
|
82
|
+
```sql
|
|
83
|
+
-- Add custom measurement types
|
|
84
|
+
INSERT INTO measurements.quantities (name, label, unit, unit_desc, description) VALUES
|
|
85
|
+
('distance', 'Distance', 'm', 'meters', 'Linear distance measurement'),
|
|
86
|
+
('weight', 'Weight', 'kg', 'kilograms', 'Mass measurement'),
|
|
87
|
+
('temperature', 'Temperature', '°C', 'celsius', 'Temperature measurement'),
|
|
88
|
+
('duration', 'Duration', 's', 'seconds', 'Time duration');
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Querying Measurement Types
|
|
92
|
+
|
|
93
|
+
```sql
|
|
94
|
+
-- Get all measurement types
|
|
95
|
+
SELECT * FROM measurements.quantities;
|
|
96
|
+
|
|
97
|
+
-- Find specific measurement
|
|
98
|
+
SELECT * FROM measurements.quantities
|
|
99
|
+
WHERE name = 'distance';
|
|
100
|
+
|
|
101
|
+
-- Get measurements by unit
|
|
102
|
+
SELECT * FROM measurements.quantities
|
|
103
|
+
WHERE unit = 'kg';
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Using Measurements in Application Tables
|
|
107
|
+
|
|
108
|
+
```sql
|
|
109
|
+
-- Create a table that references measurement types
|
|
110
|
+
CREATE TABLE sensor_readings (
|
|
111
|
+
id serial PRIMARY KEY,
|
|
112
|
+
quantity_id integer REFERENCES measurements.quantities(id),
|
|
113
|
+
value numeric NOT NULL,
|
|
114
|
+
recorded_at timestamptz DEFAULT now()
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
-- Record measurements
|
|
118
|
+
INSERT INTO sensor_readings (quantity_id, value)
|
|
119
|
+
SELECT id, 23.5
|
|
120
|
+
FROM measurements.quantities
|
|
121
|
+
WHERE name = 'temperature';
|
|
122
|
+
|
|
123
|
+
-- Query with measurement details
|
|
124
|
+
SELECT
|
|
125
|
+
sr.value,
|
|
126
|
+
q.label,
|
|
127
|
+
q.unit,
|
|
128
|
+
sr.recorded_at
|
|
129
|
+
FROM sensor_readings sr
|
|
130
|
+
JOIN measurements.quantities q ON sr.quantity_id = q.id;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Use Cases
|
|
134
|
+
|
|
135
|
+
### Performance Metrics
|
|
136
|
+
|
|
137
|
+
Track application performance measurements:
|
|
138
|
+
- Response times
|
|
139
|
+
- Query durations
|
|
140
|
+
- Resource usage
|
|
141
|
+
- Throughput rates
|
|
142
|
+
|
|
143
|
+
### IoT and Sensor Data
|
|
144
|
+
|
|
145
|
+
Store sensor readings with proper units:
|
|
146
|
+
- Temperature sensors
|
|
147
|
+
- Distance sensors
|
|
148
|
+
- Weight scales
|
|
149
|
+
- Environmental monitors
|
|
150
|
+
|
|
151
|
+
### Business Metrics
|
|
152
|
+
|
|
153
|
+
Track business measurements:
|
|
154
|
+
- Sales volumes
|
|
155
|
+
- Revenue amounts
|
|
156
|
+
- User counts
|
|
157
|
+
- Conversion rates
|
|
158
|
+
|
|
159
|
+
### Scientific Data
|
|
160
|
+
|
|
161
|
+
Store scientific measurements with proper units:
|
|
162
|
+
- Laboratory measurements
|
|
163
|
+
- Research data
|
|
164
|
+
- Experimental results
|
|
165
|
+
|
|
166
|
+
## Dependencies
|
|
167
|
+
|
|
168
|
+
- `@pgpm/verify`: Verification utilities
|
|
169
|
+
|
|
170
|
+
## Testing
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pnpm test
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Development
|
|
177
|
+
|
|
178
|
+
See the [Development](#development) section below for information on working with this package.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
### **Before You Begin**
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# 1. Install pgpm
|
|
188
|
+
npm install -g pgpm
|
|
189
|
+
|
|
190
|
+
# 2. Start Postgres (Docker or local)
|
|
191
|
+
pgpm docker start
|
|
192
|
+
|
|
193
|
+
# 3. Load PG* environment variables (PGHOST, PGUSER, ...)
|
|
194
|
+
eval "$(pgpm env)"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
### **Starting a New Project**
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# 1. Create a workspace
|
|
203
|
+
pgpm init --workspace
|
|
204
|
+
cd my-app
|
|
205
|
+
|
|
206
|
+
# 2. Create your first module
|
|
207
|
+
pgpm init
|
|
208
|
+
|
|
209
|
+
# 3. Add a migration
|
|
210
|
+
pgpm add some_change
|
|
211
|
+
|
|
212
|
+
# 4. Deploy (auto-creates database)
|
|
213
|
+
pgpm deploy --createdb
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
### **Working With an Existing Project**
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# 1. Clone and enter the project
|
|
222
|
+
git clone <repo> && cd <project>
|
|
223
|
+
|
|
224
|
+
# 2. Install dependencies
|
|
225
|
+
pnpm install
|
|
226
|
+
|
|
227
|
+
# 3. Deploy locally
|
|
228
|
+
pgpm deploy --createdb
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
### **Testing a Module Inside a Workspace**
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# 1. Install workspace deps
|
|
237
|
+
pnpm install
|
|
238
|
+
|
|
239
|
+
# 2. Enter the module directory
|
|
240
|
+
cd packages/<some-module>
|
|
241
|
+
|
|
242
|
+
# 3. Run tests in watch mode
|
|
243
|
+
pnpm test:watch
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Related Tooling
|
|
247
|
+
|
|
248
|
+
* [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.
|
|
249
|
+
* [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.
|
|
250
|
+
* [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.
|
|
251
|
+
* [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.
|
|
252
|
+
* [pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
253
|
+
* [libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
254
|
+
* [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.
|
|
255
|
+
|
|
256
|
+
## Disclaimer
|
|
257
|
+
|
|
258
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
259
|
+
|
|
260
|
+
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.
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/measurements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Measurement utilities for performance tracking and analytics",
|
|
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/verify": "0.
|
|
14
|
+
"@pgpm/verify": "0.6.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"
|
|
17
|
+
"pgpm": "^0.2.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/launchql/
|
|
21
|
+
"url": "https://github.com/launchql/pgpm-modules"
|
|
22
22
|
},
|
|
23
|
-
"homepage": "https://github.com/launchql/
|
|
23
|
+
"homepage": "https://github.com/launchql/pgpm-modules",
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/launchql/
|
|
25
|
+
"url": "https://github.com/launchql/pgpm-modules/issues"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "c7d0eae588d7a764b382a330c8b853b341b13fb2"
|
|
28
28
|
}
|
package/sqitch.plan
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
%syntax-version=1.0.0
|
|
2
|
-
%project=launchql-measurements
|
|
3
|
-
%uri=launchql-measurements
|
|
4
|
-
|
|
5
|
-
schemas/measurements/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/measurements/schema
|
|
6
|
-
schemas/measurements/tables/quantities/table [schemas/measurements/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/measurements/tables/quantities/table
|
|
7
|
-
schemas/measurements/tables/quantities/fixtures/1601076414018_fixture [schemas/measurements/schema schemas/measurements/tables/quantities/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/measurements/tables/quantities/fixtures/1601076414018_fixture
|
|
8
|
-
schemas/measurements/tables/quantities/fixtures/1601081365273_fixture [schemas/measurements/schema schemas/measurements/tables/quantities/table] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/measurements/tables/quantities/fixtures/1601081365273_fixture
|
|
File without changes
|
|
File without changes
|