File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ local json = require ' json'
2
+
3
+ local function maskSSN (ssn )
4
+ if not ssn then
5
+ return nil
6
+ end
7
+ -- Replace all but the last four digits of the SSN with "XXX-XX-"
8
+ return string.gsub (ssn , " ^(.-)(%d%d%d%d)$" , " XXX-XX-%2" )
9
+ end
10
+
11
+ local function RowToMap (row )
12
+ local map = peerdb .RowTable (row )
13
+ for col , val in pairs (map ) do
14
+ local kind = peerdb .RowColumnKind (row , col )
15
+ if col == ' ssn' then
16
+ -- Apply the maskSSN function to the SSN column
17
+ map [col ] = maskSSN (val )
18
+ elseif kind == ' bytes' or kind == ' bit' then
19
+ map [col ] = json .bin (val )
20
+ end
21
+ end
22
+ return map
23
+ end
24
+
25
+ local RKINDMAP = {
26
+ insert = string.byte (' i' , 1 ),
27
+ update = string.byte (' u' , 1 ),
28
+ delete = string.byte (' d' , 1 ),
29
+ }
30
+
31
+ function onRecord (r )
32
+ local kind = RKINDMAP [r .kind ]
33
+ if not kind then
34
+ return
35
+ end
36
+ local record = {
37
+ action = kind ,
38
+ lsn = r .checkpoint ,
39
+ time = r .commit_time ,
40
+ source = r .source ,
41
+ }
42
+ if r .old then
43
+ record .old = RowToMap (r .old )
44
+ end
45
+ if r .new then
46
+ record .new = RowToMap (r .new )
47
+ end
48
+ return json .encode (record )
49
+ end
You can’t perform that action at this time.
0 commit comments