-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummy-users.ts
52 lines (46 loc) · 1.45 KB
/
dummy-users.ts
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
import faker = require("faker");
import pg = require("pg");
const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const NUMBERS = "0123456789";
const client = new pg.Client({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DATABASE,
password: process.env.DB_PASSWORD,
port: 5432,
});
(async () => {
client.connect();
for (let i = 0; i < 100; i++) {
const al = ALPHABET.length;
let dummyCompany = "";
for (let j = 0; j < 3; j++) {
// tslint:disable-next-line: insecure-random
dummyCompany += ALPHABET[Math.floor(Math.random() * al)];
}
const nl = NUMBERS.length;
let dummyCode = "";
for (let j = 0; j < 6; j++) {
// tslint:disable-next-line: insecure-random
dummyCode += NUMBERS[Math.floor(Math.random() * nl)];
}
let dummyDept = "";
for (let j = 0; j < 4; j++) {
// tslint:disable-next-line: insecure-random
dummyDept += NUMBERS[Math.floor(Math.random() * nl)];
}
const sql = "INSERT INTO users VALUES ($1, $2, $3, $4, $5, $6)";
await client.query({
text: sql,
values: [
dummyCompany,
dummyCode,
faker.name.firstName(),
faker.name.lastName(),
faker.internet.email(),
dummyDept,
],
});
}
client.end();
})();