-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssndb.js
36 lines (32 loc) · 1.28 KB
/
ssndb.js
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
const sql = require('better-sqlite3')
const moment = require('moment')
const math = require('math')
const generator = require('fodselsnummer-generator')
var date
var numbers
var row
const gender = [ 'm', 'f']
function ssn() {
const db = require('better-sqlite3')('ssn.db', sql.OPEN_READWRITE);
db.pragma('journal_mode = WAL');
for (i=1; i< 12000; i++) {
date = moment(new Date(+(new Date()) - Math.floor(i*1000*24*3600))).format('YYYY-MM-DD');
//console.log(i, date);
for ( const person of gender) {
numbers = generator.generate(date, person);
for (j=1; j<numbers.length; j++) {
row = getRndDb(db, numbers[j],person);
}
}
}
}
function getRndDb(db, ssn, sex){
if (sex=='f') {
const row = db.prepare("select female,surname from (select female from females order by random() limit 1) join (select surname from surnames order by random() limit 1);").get();
console.log(ssn + ',' + sex + ',' + row.female + ',' + row.surname);
} else {
const row = db.prepare("select male, surname from (select male from males order by random() limit 1) join (select surname from surnames order by random() limit 1);").get();
console.log(ssn + ',' + sex + ',' + row.male + ',' + row.surname);
}
}
ssn();