From e878f2a8fe110ed5cf68e49c9902b641022c5b1d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 7 Sep 2020 12:45:54 -0700 Subject: [PATCH] Applied latest black --- sqlite_utils/db.py | 58 +++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index 9ca7dd7..6bd779a 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -659,15 +659,21 @@ class Table(Queryable): index_name = "idx_{}_{}".format( self.name.replace(" ", "_"), "_".join(columns) ) - sql = textwrap.dedent(""" + sql = ( + textwrap.dedent( + """ CREATE {unique}INDEX {if_not_exists}[{index_name}] ON [{table_name}] ({columns}); - """).strip().format( - index_name=index_name, - table_name=self.name, - columns=", ".join("[{}]".format(c) for c in columns), - unique="UNIQUE " if unique else "", - if_not_exists="IF NOT EXISTS " if if_not_exists else "", + """ + ) + .strip() + .format( + index_name=index_name, + table_name=self.name, + columns=", ".join("[{}]".format(c) for c in columns), + unique="UNIQUE " if unique else "", + if_not_exists="IF NOT EXISTS " if if_not_exists else "", + ) ) self.db.conn.execute(sql) return self @@ -780,18 +786,22 @@ class Table(Queryable): self, columns, fts_version="FTS5", create_triggers=False, tokenize=None ): "Enables FTS on the specified columns." - sql = textwrap.dedent(""" + sql = ( + textwrap.dedent( + """ CREATE VIRTUAL TABLE [{table}_fts] USING {fts_version} ( {columns},{tokenize} content=[{table}] ); - """).strip().format( - table=self.name, - columns=", ".join("[{}]".format(c) for c in columns), - fts_version=fts_version, - tokenize="\n tokenize='{}',".format(tokenize) - if tokenize - else "", + """ + ) + .strip() + .format( + table=self.name, + columns=", ".join("[{}]".format(c) for c in columns), + fts_version=fts_version, + tokenize="\n tokenize='{}',".format(tokenize) if tokenize else "", + ) ) self.db.conn.executescript(sql) self.populate_fts(columns) @@ -799,7 +809,9 @@ class Table(Queryable): if create_triggers: old_cols = ", ".join("old.[{}]".format(c) for c in columns) new_cols = ", ".join("new.[{}]".format(c) for c in columns) - triggers = textwrap.dedent(""" + triggers = ( + textwrap.dedent( + """ CREATE TRIGGER [{table}_ai] AFTER INSERT ON [{table}] BEGIN INSERT INTO [{table}_fts] (rowid, {columns}) VALUES (new.rowid, {new_cols}); END; @@ -810,11 +822,15 @@ class Table(Queryable): INSERT INTO [{table}_fts] ([{table}_fts], rowid, {columns}) VALUES('delete', old.rowid, {old_cols}); INSERT INTO [{table}_fts] (rowid, {columns}) VALUES (new.rowid, {new_cols}); END; - """).strip().format( - table=self.name, - columns=", ".join("[{}]".format(c) for c in columns), - old_cols=old_cols, - new_cols=new_cols, + """ + ) + .strip() + .format( + table=self.name, + columns=", ".join("[{}]".format(c) for c in columns), + old_cols=old_cols, + new_cols=new_cols, + ) ) self.db.conn.executescript(triggers) return self