kopia lustrzana https://github.com/simonw/datasette
Added --load-extension argument to datasette serve
Allows loading of SQLite extensions. Refs #110.pull/107/head^2
rodzic
9e27b2a0ba
commit
b7c4165346
|
@ -96,6 +96,7 @@ http://localhost:8001/History/downloads.jsono will return that data as JSON in a
|
||||||
--max_returned_rows INTEGER Max allowed rows to return at once - default is
|
--max_returned_rows INTEGER Max allowed rows to return at once - default is
|
||||||
1000. Set to 0 to disable check entirely.
|
1000. Set to 0 to disable check entirely.
|
||||||
--sql_time_limit_ms INTEGER Max time allowed for SQL queries in ms
|
--sql_time_limit_ms INTEGER Max time allowed for SQL queries in ms
|
||||||
|
--load-extension TEXT Path to a SQLite extension to load
|
||||||
--inspect-file TEXT Path to JSON file created using "datasette
|
--inspect-file TEXT Path to JSON file created using "datasette
|
||||||
build"
|
build"
|
||||||
-m, --metadata FILENAME Path to JSON file containing license/source
|
-m, --metadata FILENAME Path to JSON file containing license/source
|
||||||
|
|
|
@ -116,6 +116,10 @@ class BaseView(HTTPMethodView):
|
||||||
conn.text_factory = lambda x: str(x, 'utf-8', 'replace')
|
conn.text_factory = lambda x: str(x, 'utf-8', 'replace')
|
||||||
for name, num_args, func in self.ds.sqlite_functions:
|
for name, num_args, func in self.ds.sqlite_functions:
|
||||||
conn.create_function(name, num_args, func)
|
conn.create_function(name, num_args, func)
|
||||||
|
if self.ds.sqlite_extensions:
|
||||||
|
conn.enable_load_extension(True)
|
||||||
|
for extension in self.ds.sqlite_extensions:
|
||||||
|
conn.execute("SELECT load_extension('{}')".format(extension))
|
||||||
|
|
||||||
async def execute(self, db_name, sql, params=None, truncate=False, custom_time_limit=None):
|
async def execute(self, db_name, sql, params=None, truncate=False, custom_time_limit=None):
|
||||||
"""Executes sql against db_name in a thread"""
|
"""Executes sql against db_name in a thread"""
|
||||||
|
@ -554,7 +558,7 @@ class Datasette:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, files, num_threads=3, cache_headers=True, page_size=100,
|
self, files, num_threads=3, cache_headers=True, page_size=100,
|
||||||
max_returned_rows=1000, sql_time_limit_ms=1000, cors=False,
|
max_returned_rows=1000, sql_time_limit_ms=1000, cors=False,
|
||||||
inspect_data=None, metadata=None):
|
inspect_data=None, metadata=None, sqlite_extensions=None):
|
||||||
self.files = files
|
self.files = files
|
||||||
self.num_threads = num_threads
|
self.num_threads = num_threads
|
||||||
self.executor = futures.ThreadPoolExecutor(
|
self.executor = futures.ThreadPoolExecutor(
|
||||||
|
@ -568,6 +572,7 @@ class Datasette:
|
||||||
self._inspect = inspect_data
|
self._inspect = inspect_data
|
||||||
self.metadata = metadata or {}
|
self.metadata = metadata or {}
|
||||||
self.sqlite_functions = []
|
self.sqlite_functions = []
|
||||||
|
self.sqlite_extensions = sqlite_extensions or []
|
||||||
|
|
||||||
def inspect(self):
|
def inspect(self):
|
||||||
if not self._inspect:
|
if not self._inspect:
|
||||||
|
|
|
@ -116,9 +116,10 @@ def package(files, tag, metadata, extra_options, **extra_metadata):
|
||||||
@click.option('--page_size', default=100, help='Page size - default is 100')
|
@click.option('--page_size', default=100, help='Page size - default is 100')
|
||||||
@click.option('--max_returned_rows', default=1000, help='Max allowed rows to return at once - default is 1000. Set to 0 to disable check entirely.')
|
@click.option('--max_returned_rows', default=1000, help='Max allowed rows to return at once - default is 1000. Set to 0 to disable check entirely.')
|
||||||
@click.option('--sql_time_limit_ms', default=1000, help='Max time allowed for SQL queries in ms')
|
@click.option('--sql_time_limit_ms', default=1000, help='Max time allowed for SQL queries in ms')
|
||||||
|
@click.option('--load-extension', multiple=True, help="Path to a SQLite extension to load")
|
||||||
@click.option('--inspect-file', help='Path to JSON file created using "datasette build"')
|
@click.option('--inspect-file', help='Path to JSON file created using "datasette build"')
|
||||||
@click.option('-m', '--metadata', type=click.File(mode='r'), help='Path to JSON file containing license/source metadata')
|
@click.option('-m', '--metadata', type=click.File(mode='r'), help='Path to JSON file containing license/source metadata')
|
||||||
def serve(files, host, port, debug, reload, cors, page_size, max_returned_rows, sql_time_limit_ms, inspect_file, metadata):
|
def serve(files, host, port, debug, reload, cors, page_size, max_returned_rows, sql_time_limit_ms, load_extension, inspect_file, metadata):
|
||||||
"""Serve up specified SQLite database files with a web UI"""
|
"""Serve up specified SQLite database files with a web UI"""
|
||||||
if reload:
|
if reload:
|
||||||
import hupper
|
import hupper
|
||||||
|
@ -142,6 +143,7 @@ def serve(files, host, port, debug, reload, cors, page_size, max_returned_rows,
|
||||||
sql_time_limit_ms=sql_time_limit_ms,
|
sql_time_limit_ms=sql_time_limit_ms,
|
||||||
inspect_data=inspect_data,
|
inspect_data=inspect_data,
|
||||||
metadata=metadata_data,
|
metadata=metadata_data,
|
||||||
|
sqlite_extensions=load_extension,
|
||||||
)
|
)
|
||||||
# Force initial hashing/table counting
|
# Force initial hashing/table counting
|
||||||
ds.inspect()
|
ds.inspect()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
sphinx-autobuild . _build/html
|
|
@ -118,6 +118,17 @@ datasette serve options
|
||||||
--debug Enable debug mode - useful for development
|
--debug Enable debug mode - useful for development
|
||||||
--reload Automatically reload if code change detected -
|
--reload Automatically reload if code change detected -
|
||||||
useful for development
|
useful for development
|
||||||
--cors Enable CORS by
|
--cors Enable CORS by serving Access-Control-Allow-
|
||||||
|
Origin: *
|
||||||
|
--page_size INTEGER Page size - default is 100
|
||||||
|
--max_returned_rows INTEGER Max allowed rows to return at once - default is
|
||||||
|
1000. Set to 0 to disable check entirely.
|
||||||
|
--sql_time_limit_ms INTEGER Max time allowed for SQL queries in ms
|
||||||
|
--load-extension TEXT Path to a SQLite extension to load
|
||||||
|
--inspect-file TEXT Path to JSON file created using "datasette
|
||||||
|
build"
|
||||||
|
-m, --metadata FILENAME Path to JSON file containing license/source
|
||||||
|
metadata
|
||||||
|
--help Show this message and exit.
|
||||||
|
|
||||||
.. _Zeit Now: https://zeit.co/now
|
.. _Zeit Now: https://zeit.co/now
|
||||||
|
|
Ładowanie…
Reference in New Issue