Skip to content

Commit

Permalink
feat: add support to specify tables in list of columns (#13)
Browse files Browse the repository at this point in the history
you can also specify which table you wnt to replace a column in
  • Loading branch information
imreACTmd authored Jan 3, 2022
1 parent 2733bad commit bc6638d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Specifying another list via `--list` replace the default automatically anonymize
email,name,description,address,city,country,phone,comment,birthdate
```

You can also specify the table for a column using the dot notation:

```csv
public.user.email,public.product.description,email,name
```

#### Customize replacements

You can also choose which faker function you want to use to replace data (default is `faker.random.word`):
Expand Down Expand Up @@ -70,10 +76,6 @@ module.exports = {
};
```

### Memory limit

Use `-m` to change `pg_dump` output memory limit (e.g: `512`)

### Locale (i18n)

Use `-l` to change the locale used by faker (default: `en`)
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class PgAnonymizer extends Command {
}),
pgDumpOutputMemory: flags.string({
char: "m",
description: "max memory used to get output from pg_dump in MB",
default: "256",
description: "Obsolete, not needed any more: max memory used to get output from pg_dump in MB",
default: "0",
}),
};

Expand Down Expand Up @@ -112,7 +112,8 @@ class PgAnonymizer extends Command {
.map((e) => e.toLowerCase());

indices = cols.reduce((acc: Number[], value, key) => {
if (list.find((l) => l.col === value)) acc.push(key);
if (list.find((l) => l.col === value)) acc.push(key)
else if (list.find((l) => l.col === table + '.' + value)) acc.push(key);
return acc;
}, []);

Expand All @@ -127,9 +128,14 @@ class PgAnonymizer extends Command {
.split("\t")
.map((v, k) => {
if (indices.includes(k)) {
const replacement = list.find(
let replacement = list.find(
(l) => l.col === cols[k]
)?.replacement;
if (!replacement) {
replacement = list.find(
(l) => l.col === table + '.' + cols[k]
)?.replacement;
}
if (replacement) {
if (replacement.startsWith("faker.")) {
const [_one, two, three] = replacement.split(".");
Expand Down

0 comments on commit bc6638d

Please sign in to comment.