mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-14 12:34:10 +02:00
Format with Black, remove unused imports, fix implicitly concatenated string
This commit is contained in:
parent
15f15933b1
commit
9c9fdc3790
11 changed files with 95 additions and 112 deletions
|
|
@ -2137,9 +2137,7 @@ def search(
|
|||
table_columns = table_obj.columns_dict
|
||||
for c in column:
|
||||
if c not in table_columns:
|
||||
raise click.ClickException(
|
||||
f"Table '{dbtable}' has no column '{c}"
|
||||
)
|
||||
raise click.ClickException(f"Table '{dbtable}' has no column '{c}")
|
||||
sql = table_obj.search_sql(columns=column, order_by=order, limit=limit)
|
||||
if show_sql:
|
||||
click.echo(sql)
|
||||
|
|
|
|||
|
|
@ -28,11 +28,8 @@ from typing import (
|
|||
cast,
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Union,
|
||||
Optional,
|
||||
List,
|
||||
Tuple,
|
||||
)
|
||||
from collections.abc import Generator, Iterable
|
||||
import uuid
|
||||
|
|
@ -590,9 +587,7 @@ class Database:
|
|||
query += '"'
|
||||
bits = _quote_fts_re.split(query)
|
||||
bits = [b for b in bits if b and b != '""']
|
||||
return " ".join(
|
||||
f'"{bit}"' if not bit.startswith('"') else bit for bit in bits
|
||||
)
|
||||
return " ".join(f'"{bit}"' if not bit.startswith('"') else bit for bit in bits)
|
||||
|
||||
def quote_default_value(self, value: str) -> str:
|
||||
if any(
|
||||
|
|
@ -680,9 +675,7 @@ class Database:
|
|||
try:
|
||||
table_name = f"t{secrets.token_hex(16)}"
|
||||
with self.conn:
|
||||
self.conn.execute(
|
||||
f"create table {table_name} (name text) strict"
|
||||
)
|
||||
self.conn.execute(f"create table {table_name} (name text) strict")
|
||||
self.conn.execute(f"drop table {table_name}")
|
||||
return True
|
||||
except Exception:
|
||||
|
|
@ -907,9 +900,7 @@ class Database:
|
|||
if fk.other_column != "rowid" and not any(
|
||||
c for c in self[fk.other_table].columns if c.name == fk.other_column
|
||||
):
|
||||
raise AlterError(
|
||||
f"No such column: {fk.other_table}.{fk.other_column}"
|
||||
)
|
||||
raise AlterError(f"No such column: {fk.other_table}.{fk.other_column}")
|
||||
|
||||
column_defs = []
|
||||
# ensure pk is a tuple
|
||||
|
|
@ -1592,9 +1583,7 @@ class Table(Queryable):
|
|||
for row in self.db.execute_returning_dicts(sql):
|
||||
index_name = row["name"]
|
||||
index_name_quoted = (
|
||||
f'"{index_name}"'
|
||||
if not index_name.startswith('"')
|
||||
else index_name
|
||||
f'"{index_name}"' if not index_name.startswith('"') else index_name
|
||||
)
|
||||
column_sql = f"PRAGMA index_info({index_name_quoted})"
|
||||
columns = []
|
||||
|
|
@ -1616,9 +1605,7 @@ class Table(Queryable):
|
|||
for row in self.db.execute_returning_dicts(sql):
|
||||
index_name = row["name"]
|
||||
index_name_quoted = (
|
||||
f'"{index_name}"'
|
||||
if not index_name.startswith('"')
|
||||
else index_name
|
||||
f'"{index_name}"' if not index_name.startswith('"') else index_name
|
||||
)
|
||||
column_sql = f"PRAGMA index_xinfo({index_name_quoted})"
|
||||
index_columns = []
|
||||
|
|
@ -1971,15 +1958,11 @@ class Table(Queryable):
|
|||
sqls.append(copy_sql)
|
||||
# Drop (or keep) the old table
|
||||
if keep_table:
|
||||
sqls.append(
|
||||
f"ALTER TABLE [{self.name}] RENAME TO [{keep_table}];"
|
||||
)
|
||||
sqls.append(f"ALTER TABLE [{self.name}] RENAME TO [{keep_table}];")
|
||||
else:
|
||||
sqls.append(f"DROP TABLE [{self.name}];")
|
||||
# Rename the new one
|
||||
sqls.append(
|
||||
f"ALTER TABLE [{new_table_name}] RENAME TO [{self.name}];"
|
||||
)
|
||||
sqls.append(f"ALTER TABLE [{new_table_name}] RENAME TO [{self.name}];")
|
||||
# Re-add existing indexes
|
||||
for index in self.indexes:
|
||||
if index.origin != "pk":
|
||||
|
|
@ -2152,9 +2135,7 @@ class Table(Queryable):
|
|||
suffix = None
|
||||
created_index_name = None
|
||||
while True:
|
||||
created_index_name = (
|
||||
f"{index_name}_{suffix}" if suffix else index_name
|
||||
)
|
||||
created_index_name = f"{index_name}_{suffix}" if suffix else index_name
|
||||
sql = (
|
||||
textwrap.dedent(
|
||||
"""
|
||||
|
|
@ -2510,9 +2491,7 @@ class Table(Queryable):
|
|||
"""
|
||||
)
|
||||
.strip()
|
||||
.format(
|
||||
table=self.name, columns=", ".join(f"[{c}]" for c in columns)
|
||||
)
|
||||
.format(table=self.name, columns=", ".join(f"[{c}]" for c in columns))
|
||||
)
|
||||
self.db.executescript(sql)
|
||||
return self
|
||||
|
|
@ -3677,9 +3656,9 @@ class Table(Queryable):
|
|||
most_common_results = None
|
||||
least_common_results = None
|
||||
if num_distinct == 1:
|
||||
value = db.execute(
|
||||
f"select [{column}] from [{table}] limit 1"
|
||||
).fetchone()[0]
|
||||
value = db.execute(f"select [{column}] from [{table}] limit 1").fetchone()[
|
||||
0
|
||||
]
|
||||
most_common_results = [(truncate(value), total_rows)]
|
||||
elif num_distinct != total_rows:
|
||||
if most_common:
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import json
|
|||
import os
|
||||
import sys
|
||||
from . import recipes
|
||||
from typing import Dict, cast, BinaryIO, Optional, Tuple, Type
|
||||
from typing import cast, BinaryIO, Optional
|
||||
from collections.abc import Iterable
|
||||
|
||||
import click
|
||||
|
|
@ -226,9 +226,7 @@ def _extra_key_strategy(
|
|||
yield row
|
||||
elif not extras_key:
|
||||
extras = row.pop(None) # type: ignore
|
||||
raise RowError(
|
||||
f"Row {row} contained these extra values: {extras}"
|
||||
)
|
||||
raise RowError(f"Row {row} contained these extra values: {extras}")
|
||||
else:
|
||||
row[extras_key] = row.pop(None) # type: ignore
|
||||
yield row
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue