mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
--crossdb option for joining across databases (#1232)
* Test for cross-database join, refs #283 * Warn if --crossdb used with more than 10 DBs, refs #283 * latest.datasette.io demo of --crossdb joins, refs #283 * Show attached databases on /_memory page, refs #283 * Documentation for cross-database queries, refs #283
This commit is contained in:
parent
4df548e766
commit
6f41c8a2be
13 changed files with 215 additions and 8 deletions
|
|
@ -12,7 +12,7 @@ from subprocess import call
|
|||
import sys
|
||||
from runpy import run_module
|
||||
import webbrowser
|
||||
from .app import Datasette, DEFAULT_SETTINGS, SETTINGS, pm
|
||||
from .app import Datasette, DEFAULT_SETTINGS, SETTINGS, SQLITE_LIMIT_ATTACHED, pm
|
||||
from .utils import (
|
||||
StartupError,
|
||||
check_connection,
|
||||
|
|
@ -410,6 +410,11 @@ def uninstall(packages, yes):
|
|||
is_flag=True,
|
||||
help="Create database files if they do not exist",
|
||||
)
|
||||
@click.option(
|
||||
"--crossdb",
|
||||
is_flag=True,
|
||||
help="Enable cross-database joins using the /_memory database",
|
||||
)
|
||||
@click.option(
|
||||
"--ssl-keyfile",
|
||||
help="SSL key file",
|
||||
|
|
@ -442,6 +447,7 @@ def serve(
|
|||
pdb,
|
||||
open_browser,
|
||||
create,
|
||||
crossdb,
|
||||
ssl_keyfile,
|
||||
ssl_certfile,
|
||||
return_instance=False,
|
||||
|
|
@ -499,6 +505,7 @@ def serve(
|
|||
secret=secret,
|
||||
version_note=version_note,
|
||||
pdb=pdb,
|
||||
crossdb=crossdb,
|
||||
)
|
||||
|
||||
# if files is a single directory, use that as config_dir=
|
||||
|
|
@ -591,3 +598,15 @@ async def check_databases(ds):
|
|||
raise click.UsageError(
|
||||
f"Connection to {database.path} failed check: {str(e.args[0])}"
|
||||
)
|
||||
# If --crossdb and more than SQLITE_LIMIT_ATTACHED show warning
|
||||
if (
|
||||
ds.crossdb
|
||||
and len([db for db in ds.databases.values() if not db.is_memory])
|
||||
> SQLITE_LIMIT_ATTACHED
|
||||
):
|
||||
msg = (
|
||||
"Warning: --crossdb only works with the first {} attached databases".format(
|
||||
SQLITE_LIMIT_ATTACHED
|
||||
)
|
||||
)
|
||||
click.echo(click.style(msg, bold=True, fg="yellow"), err=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue