@pgpm/faker 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,7 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
create fake data in PostgreSQL
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@pgpm/faker` provides a comprehensive set of fake data generation functions directly in PostgreSQL. Perfect for seeding test databases, creating demo data, and development environments. All functions are implemented in pure plpgsql and return realistic-looking data without external dependencies.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Geographic Data**: Latitude/longitude coordinates, addresses by state
|
|
12
|
+
- **Text Generation**: Sentences, paragraphs, tags, names
|
|
13
|
+
- **Temporal Data**: Random timestamps, dates, intervals
|
|
14
|
+
- **Numeric Data**: Random integers and floats
|
|
15
|
+
- **Contact Information**: Email, phone, IP addresses
|
|
16
|
+
- **File & Media**: URLs, images, profile pictures, attachments
|
|
17
|
+
- **Business Data**: Company names, usernames, tokens
|
|
18
|
+
- **State-Aware**: Filter data by US state codes
|
|
19
|
+
- **Pure plpgsql**: No external dependencies required
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
If you have `pgpm` installed:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pgpm install @pgpm/faker
|
|
27
|
+
pgpm deploy
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This is a quick way to get started. The sections below provide more detailed installation options.
|
|
31
|
+
|
|
32
|
+
### Prerequisites
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Install pgpm globally
|
|
36
|
+
npm install -g pgpm
|
|
37
|
+
|
|
38
|
+
# Start PostgreSQL
|
|
39
|
+
pgpm docker start
|
|
40
|
+
|
|
41
|
+
# Set environment variables
|
|
42
|
+
eval "$(pgpm env)"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Deploy
|
|
46
|
+
|
|
47
|
+
#### Option 1: Deploy by installing with pgpm
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pgpm install @pgpm/faker
|
|
51
|
+
pgpm deploy
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Option 2: Deploy from Package Directory
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cd packages/utils/faker
|
|
58
|
+
pgpm deploy --createdb
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Option 3: Deploy from Workspace Root
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Install workspace dependencies
|
|
65
|
+
pnpm install
|
|
66
|
+
|
|
67
|
+
# Deploy with dependencies
|
|
68
|
+
pgpm deploy mydb1 --yes --createdb
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
6
72
|
|
|
7
73
|
## state, city, zip
|
|
8
74
|
|
|
@@ -368,7 +434,79 @@ select faker.lnglat();
|
|
|
368
434
|
-- (-74.0205,40.316)
|
|
369
435
|
```
|
|
370
436
|
|
|
371
|
-
|
|
437
|
+
## Use Cases
|
|
438
|
+
|
|
439
|
+
### Seeding Test Databases
|
|
440
|
+
|
|
441
|
+
Generate realistic test data for development:
|
|
442
|
+
|
|
443
|
+
```sql
|
|
444
|
+
-- Create test users with fake data
|
|
445
|
+
INSERT INTO users (name, email, created_at)
|
|
446
|
+
SELECT
|
|
447
|
+
faker.fullname(),
|
|
448
|
+
faker.email(),
|
|
449
|
+
faker.timestamptz()
|
|
450
|
+
FROM generate_series(1, 100);
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### Geographic Testing
|
|
454
|
+
|
|
455
|
+
Test location-based features:
|
|
456
|
+
|
|
457
|
+
```sql
|
|
458
|
+
-- Create test locations with coordinates
|
|
459
|
+
INSERT INTO locations (lat, lng, address)
|
|
460
|
+
SELECT
|
|
461
|
+
(faker.lnglat()).lat,
|
|
462
|
+
(faker.lnglat()).lng,
|
|
463
|
+
faker.address()
|
|
464
|
+
FROM generate_series(1, 50);
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Content Generation
|
|
468
|
+
|
|
469
|
+
Generate fake content for testing:
|
|
470
|
+
|
|
471
|
+
```sql
|
|
472
|
+
-- Create blog posts
|
|
473
|
+
INSERT INTO posts (title, content, tags, published_at)
|
|
474
|
+
SELECT
|
|
475
|
+
faker.word() || ' ' || faker.word(),
|
|
476
|
+
faker.paragraph(),
|
|
477
|
+
faker.tags(),
|
|
478
|
+
faker.timestamptz()
|
|
479
|
+
FROM generate_series(1, 100);
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Demo Data
|
|
483
|
+
|
|
484
|
+
Create realistic demo data for presentations:
|
|
485
|
+
|
|
486
|
+
```sql
|
|
487
|
+
-- E-commerce orders
|
|
488
|
+
INSERT INTO orders (customer_name, phone, total, order_date)
|
|
489
|
+
SELECT
|
|
490
|
+
faker.fullname(),
|
|
491
|
+
faker.phone(),
|
|
492
|
+
faker.float(10, 1000),
|
|
493
|
+
faker.date()
|
|
494
|
+
FROM generate_series(1, 1000);
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## Testing
|
|
498
|
+
|
|
499
|
+
```bash
|
|
500
|
+
pnpm test
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## Dependencies
|
|
504
|
+
|
|
505
|
+
None - this is a pure plpgsql implementation.
|
|
506
|
+
|
|
507
|
+
---
|
|
508
|
+
|
|
509
|
+
## Development
|
|
372
510
|
|
|
373
511
|
## start the postgres db process
|
|
374
512
|
|
|
@@ -409,30 +547,110 @@ yarn test:watch
|
|
|
409
547
|
Create a new folder in `packages/`
|
|
410
548
|
|
|
411
549
|
```sh
|
|
412
|
-
|
|
550
|
+
pgpm init
|
|
413
551
|
```
|
|
414
552
|
|
|
415
553
|
Then, run a generator:
|
|
416
554
|
|
|
417
555
|
```sh
|
|
418
|
-
|
|
556
|
+
pgpm generate
|
|
419
557
|
```
|
|
420
558
|
|
|
421
559
|
You can also add arguments if you already know what you want to do:
|
|
422
560
|
|
|
423
561
|
```sh
|
|
424
|
-
|
|
425
|
-
|
|
562
|
+
pgpm generate schema --schema myschema
|
|
563
|
+
pgpm generate table --schema myschema --table mytable
|
|
426
564
|
```
|
|
427
565
|
|
|
428
566
|
## deploy code as extensions
|
|
429
567
|
|
|
430
|
-
`cd` into `packages/<module>`, and run `
|
|
568
|
+
`cd` into `packages/<module>`, and run `pgpm package`. This will make an sql file in `packages/<module>/sql/` used for `CREATE EXTENSION` calls to install your sqitch module as an extension.
|
|
431
569
|
|
|
432
570
|
## recursive deploy
|
|
433
571
|
|
|
434
572
|
You can also deploy all modules utilizing versioning as sqtich modules. Remove `--createdb` if you already created your db:
|
|
435
573
|
|
|
436
574
|
```sh
|
|
437
|
-
|
|
575
|
+
pgpm deploy mydb1 --yes --createdb
|
|
438
576
|
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
### **Before You Begin**
|
|
581
|
+
|
|
582
|
+
```bash
|
|
583
|
+
# 1. Install pgpm
|
|
584
|
+
npm install -g pgpm
|
|
585
|
+
|
|
586
|
+
# 2. Start Postgres (Docker or local)
|
|
587
|
+
pgpm docker start
|
|
588
|
+
|
|
589
|
+
# 3. Load PG* environment variables (PGHOST, PGUSER, ...)
|
|
590
|
+
eval "$(pgpm env)"
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
---
|
|
594
|
+
|
|
595
|
+
### **Starting a New Project**
|
|
596
|
+
|
|
597
|
+
```bash
|
|
598
|
+
# 1. Create a workspace
|
|
599
|
+
pgpm init --workspace
|
|
600
|
+
cd my-app
|
|
601
|
+
|
|
602
|
+
# 2. Create your first module
|
|
603
|
+
pgpm init
|
|
604
|
+
|
|
605
|
+
# 3. Add a migration
|
|
606
|
+
pgpm add some_change
|
|
607
|
+
|
|
608
|
+
# 4. Deploy (auto-creates database)
|
|
609
|
+
pgpm deploy --createdb
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
---
|
|
613
|
+
|
|
614
|
+
### **Working With an Existing Project**
|
|
615
|
+
|
|
616
|
+
```bash
|
|
617
|
+
# 1. Clone and enter the project
|
|
618
|
+
git clone <repo> && cd <project>
|
|
619
|
+
|
|
620
|
+
# 2. Install dependencies
|
|
621
|
+
pnpm install
|
|
622
|
+
|
|
623
|
+
# 3. Deploy locally
|
|
624
|
+
pgpm deploy --createdb
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
---
|
|
628
|
+
|
|
629
|
+
### **Testing a Module Inside a Workspace**
|
|
630
|
+
|
|
631
|
+
```bash
|
|
632
|
+
# 1. Install workspace deps
|
|
633
|
+
pnpm install
|
|
634
|
+
|
|
635
|
+
# 2. Enter the module directory
|
|
636
|
+
cd packages/<some-module>
|
|
637
|
+
|
|
638
|
+
# 3. Run tests in watch mode
|
|
639
|
+
pnpm test:watch
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
## Related Tooling
|
|
643
|
+
|
|
644
|
+
* [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.
|
|
645
|
+
* [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.
|
|
646
|
+
* [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.
|
|
647
|
+
* [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.
|
|
648
|
+
* [pgsql-parser](https://github.com/launchql/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
649
|
+
* [libpg-query-node](https://github.com/launchql/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
650
|
+
* [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.
|
|
651
|
+
|
|
652
|
+
## Disclaimer
|
|
653
|
+
|
|
654
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
655
|
+
|
|
656
|
+
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/launchql-faker.control
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# launchql-faker extension
|
|
2
2
|
comment = 'launchql-faker extension'
|
|
3
|
-
default_version = '0.
|
|
3
|
+
default_version = '0.5.0'
|
|
4
4
|
module_pathname = '$libdir/launchql-faker'
|
|
5
5
|
requires = 'citext,pgcrypto,plpgsql,uuid-ossp,launchql-types,launchql-verify'
|
|
6
6
|
relocatable = false
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/faker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Fake data generation utilities for testing and development",
|
|
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.6.0",
|
|
15
|
+
"@pgpm/verify": "0.6.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"
|
|
18
|
+
"pgpm": "^0.2.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/launchql/
|
|
22
|
+
"url": "https://github.com/launchql/pgpm-modules"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/launchql/
|
|
24
|
+
"homepage": "https://github.com/launchql/pgpm-modules",
|
|
25
25
|
"bugs": {
|
|
26
|
-
"url": "https://github.com/launchql/
|
|
26
|
+
"url": "https://github.com/launchql/pgpm-modules/issues"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "c7d0eae588d7a764b382a330c8b853b341b13fb2"
|
|
29
29
|
}
|
|
File without changes
|
|
File without changes
|