l.s.d.sort_sql : module documentation

Part of lp.services.database

Sort SQL dumps.

This library provides functions for the script sort_sql.py, which resides in database/schema/.

Class Parser Parse an SQL dump into logical lines.
Function print_lines_sorted Print a set of (value, line) pairs in sorted order.
def print_lines_sorted(file, lines):

Print a set of (value, line) pairs in sorted order.

Sorting only occurs within blocks of statements.

>>> lines = [
...     (10, "INSERT INTO foo (id, x) VALUES (10, 'data');"),
...     (4, "INSERT INTO foo (id, x) VALUES (4, 'data\nmore\nmore');"),
...     (7, "INSERT INTO foo (id, x) VALUES (7, 'data');"),
...     (1, "INSERT INTO foo (id, x) VALUES (1, 'data');"),
...     (None, ""),
...     (2, "INSERT INTO baz (id, x) VALUES (2, 'data');"),
...     (1, "INSERT INTO baz (id, x) VALUES (1, 'data');"),
...     ]
>>> import sys
>>> print_lines_sorted(sys.stdout, lines)
INSERT INTO foo (id, x) VALUES (1, 'data');
INSERT INTO foo (id, x) VALUES (4, 'data
more
more');
INSERT INTO foo (id, x) VALUES (7, 'data');
INSERT INTO foo (id, x) VALUES (10, 'data');
<BLANKLINE>
INSERT INTO baz (id, x) VALUES (1, 'data');
INSERT INTO baz (id, x) VALUES (2, 'data');
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.