Sha256: f51205cbfed648ad4ad70d9170c9e0825a39d684c5142c2d2bb18e272e32c506
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
class MyObfuscate class Postgres include MyObfuscate::CopyStatementParser # Copy statements contain the column values tab seperated like so: # blah blah blah blah # which we want to turn into: # [['blah','blah','blah','blah']] # # We wrap it in an array to keep it consistent with MySql bulk # obfuscation (multiple rows per insert statement) def rows_to_be_inserted(line) line.gsub!(/\n$/,"") row = line.split(/\t/) row.collect! do |value| if value == "\\N" nil else value end end [row] end def parse_copy_statement(line) if regex_match = /^\s*COPY (.*?) \((.*?)\) FROM\s*/i.match(line) { :table_name => regex_match[1].to_sym, :column_names => regex_match[2].split(/\s*,\s*/).map(&:to_sym) } end end def make_insert_statement(table_name, column_names, values) values.join("\t") end def make_valid_value_string(value) if value.nil? "\\N" else value end end def parse_insert_statement(line) /^\s*INSERT INTO/i.match(line) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
my_obfuscate-0.5.1 | lib/my_obfuscate/postgres.rb |
my_obfuscate-0.5.0 | lib/my_obfuscate/postgres.rb |