kopia lustrzana https://github.com/simonw/datasette
Rename execute_against_connection_in_thread() to execute_fn(), refs #685
rodzic
182e5c8745
commit
69e3a855dd
|
@ -388,7 +388,7 @@ async def check_databases(ds):
|
||||||
# to confirm they are all usable
|
# to confirm they are all usable
|
||||||
for database in list(ds.databases.values()):
|
for database in list(ds.databases.values()):
|
||||||
try:
|
try:
|
||||||
await database.execute_against_connection_in_thread(check_connection)
|
await database.execute_fn(check_connection)
|
||||||
except SpatialiteConnectionProblem:
|
except SpatialiteConnectionProblem:
|
||||||
raise click.UsageError(
|
raise click.UsageError(
|
||||||
"It looks like you're trying to load a SpatiaLite"
|
"It looks like you're trying to load a SpatiaLite"
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Database:
|
||||||
result = e
|
result = e
|
||||||
task.reply_queue.sync_q.put(result)
|
task.reply_queue.sync_q.put(result)
|
||||||
|
|
||||||
async def execute_against_connection_in_thread(self, fn):
|
async def execute_fn(self, fn):
|
||||||
def in_thread():
|
def in_thread():
|
||||||
conn = getattr(connections, self.name, None)
|
conn = getattr(connections, self.name, None)
|
||||||
if not conn:
|
if not conn:
|
||||||
|
@ -163,9 +163,7 @@ class Database:
|
||||||
return Results(rows, False, cursor.description)
|
return Results(rows, False, cursor.description)
|
||||||
|
|
||||||
with trace("sql", database=self.name, sql=sql.strip(), params=params):
|
with trace("sql", database=self.name, sql=sql.strip(), params=params):
|
||||||
results = await self.execute_against_connection_in_thread(
|
results = await self.execute_fn(sql_operation_in_thread)
|
||||||
sql_operation_in_thread
|
|
||||||
)
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -223,19 +221,13 @@ class Database:
|
||||||
return [r[0] for r in results.rows]
|
return [r[0] for r in results.rows]
|
||||||
|
|
||||||
async def table_columns(self, table):
|
async def table_columns(self, table):
|
||||||
return await self.execute_against_connection_in_thread(
|
return await self.execute_fn(lambda conn: table_columns(conn, table))
|
||||||
lambda conn: table_columns(conn, table)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def primary_keys(self, table):
|
async def primary_keys(self, table):
|
||||||
return await self.execute_against_connection_in_thread(
|
return await self.execute_fn(lambda conn: detect_primary_keys(conn, table))
|
||||||
lambda conn: detect_primary_keys(conn, table)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def fts_table(self, table):
|
async def fts_table(self, table):
|
||||||
return await self.execute_against_connection_in_thread(
|
return await self.execute_fn(lambda conn: detect_fts(conn, table))
|
||||||
lambda conn: detect_fts(conn, table)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def label_column_for_table(self, table):
|
async def label_column_for_table(self, table):
|
||||||
explicit_label_column = self.ds.table_metadata(self.name, table).get(
|
explicit_label_column = self.ds.table_metadata(self.name, table).get(
|
||||||
|
@ -244,9 +236,7 @@ class Database:
|
||||||
if explicit_label_column:
|
if explicit_label_column:
|
||||||
return explicit_label_column
|
return explicit_label_column
|
||||||
# If a table has two columns, one of which is ID, then label_column is the other one
|
# If a table has two columns, one of which is ID, then label_column is the other one
|
||||||
column_names = await self.execute_against_connection_in_thread(
|
column_names = await self.execute_fn(lambda conn: table_columns(conn, table))
|
||||||
lambda conn: table_columns(conn, table)
|
|
||||||
)
|
|
||||||
# Is there a name or title column?
|
# Is there a name or title column?
|
||||||
name_or_title = [c for c in column_names if c in ("name", "title")]
|
name_or_title = [c for c in column_names if c in ("name", "title")]
|
||||||
if name_or_title:
|
if name_or_title:
|
||||||
|
@ -261,7 +251,7 @@ class Database:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def foreign_keys_for_table(self, table):
|
async def foreign_keys_for_table(self, table):
|
||||||
return await self.execute_against_connection_in_thread(
|
return await self.execute_fn(
|
||||||
lambda conn: get_outbound_foreign_keys(conn, table)
|
lambda conn: get_outbound_foreign_keys(conn, table)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -279,9 +269,7 @@ class Database:
|
||||||
)
|
)
|
||||||
).rows
|
).rows
|
||||||
]
|
]
|
||||||
has_spatialite = await self.execute_against_connection_in_thread(
|
has_spatialite = await self.execute_fn(detect_spatialite)
|
||||||
detect_spatialite
|
|
||||||
)
|
|
||||||
if has_spatialite:
|
if has_spatialite:
|
||||||
# Also hide Spatialite internal tables
|
# Also hide Spatialite internal tables
|
||||||
hidden_tables += [
|
hidden_tables += [
|
||||||
|
@ -329,10 +317,10 @@ class Database:
|
||||||
return [r[0] for r in results.rows]
|
return [r[0] for r in results.rows]
|
||||||
|
|
||||||
async def get_all_foreign_keys(self):
|
async def get_all_foreign_keys(self):
|
||||||
return await self.execute_against_connection_in_thread(get_all_foreign_keys)
|
return await self.execute_fn(get_all_foreign_keys)
|
||||||
|
|
||||||
async def get_outbound_foreign_keys(self, table):
|
async def get_outbound_foreign_keys(self, table):
|
||||||
return await self.execute_against_connection_in_thread(
|
return await self.execute_fn(
|
||||||
lambda conn: get_outbound_foreign_keys(conn, table)
|
lambda conn: get_outbound_foreign_keys(conn, table)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue