How to use the pgtricks.pg_dump_splitsort.Matcher function in pgtricks

To help you get started, we’ve selected a few pgtricks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github akaihola / pgtricks / pgtricks / pg_dump_splitsort.py View on Github external
output: Optional[IO[str]] = None
    buf: List[str] = []

    def flush() -> None:
        cast(IO[str], output).writelines(buf)
        buf[:] = []

    def new_output(filename: str) -> IO[str]:
        if output:
            output.close()
        return open(os.path.join(directory, filename), 'w')

    copy_lines: Optional[List[str]] = None
    counter = 0
    output = new_output('0000_prologue.sql')
    matcher = Matcher()

    for line in open(sql_filepath):
        if copy_lines is None:
            if line in ('\n', '--\n'):
                buf.append(line)
            elif line.startswith('SET search_path = '):
                flush()
                buf.append(line)
            else:
                if matcher.match(DATA_COMMENT_RE, line):
                    counter += 1
                    output = new_output(
                        '{counter:04}_{schema}.{table}.sql'.format(
                            counter=counter,
                            schema=matcher.group('schema'),
                            table=matcher.group('table')))

pgtricks

PostgreSQL utilities

BSD-3-Clause
Latest version published 8 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages