mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Applied latest black
This commit is contained in:
parent
59e3d4d171
commit
e878f2a8fe
1 changed files with 37 additions and 21 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue