Make it easier to populate your PostgreSQL and MySQL test environments, creating inserts with consistent random data. With clear language, you can focus on what makes your scenario unique.
Example: insert an inactive user which name is John. John must have 2 addresses. For all other params, I accept a random (but still valid) value.
// some pre-configurations steps that will be explained below...
database.insert('t_user', { name: 'John', is_active: false });
database.insert('t_address');
database.insert('t_address');
console.log(database.toSQL().join("\n"));
console.log(database.rollback().join("\n"));
The result will be:
INSERT INTO "t_user" ("id", "name", "surname", "email", "gender", "is_active", "birth", "created_at", "updated_at") VALUES (1, 'John', 'Bryant', 'john@doe.com', 'M', false, '2001-12-03', '2019-05-18 06:21:46', now());
INSERT INTO "t_address" ("id", "user_id", "street", "city", "country", "postcode", "phone", "receiver_name") VALUES (1, 1, 'Mofup Mill', 'Zadowwip', 'Congo - Brazzaville', '11216-075', '86 0451-9903', 'Norman Jackson');
INSERT INTO "t_address" ("id", "user_id", "street", "city", "country", "postcode", "phone", "receiver_name") VALUES (2, 1, 'Hepvep Grove', 'Jellebo', 'Puerto Rico', '05799-907', '36 3499-6594', 'Lucas Norris');
/* --- ROLLBACK */
DELETE FROM "t_address" WHERE "id"=2;
DELETE FROM "t_address" WHERE "id"=1;
DELETE FROM "t_user" WHERE "id"=1;
Available databases:
- Postgres
- MySQL
Others databases will be added soon.
If you don't want to wait: check New Database Docs.
Examples
Clone random-db-populator-example. There you will find:
Wiki
Check full documentation.
Tip: Use typescript version. It will make it easier!