/datasette-rewrite-sql

A Datasette hook to inspect/rewrite the SQL users run.

Primary LanguagePythonApache License 2.0Apache-2.0

datasette-rewrite-sql

PyPI Changelog Tests License

Adds a rewrite_sql hook to Datasette.

Warning

This hook is added by monkey-patching Datasette. YOLO, but also, govern yourself accordingly.

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-rewrite-sql

Usage

Write a hook like:

from datasette import hookimpl

@hookimpl
def rewrite_sql(sql):
  if sql == 'select 123':
    return 'select 234'

  return sql

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-rewrite-sql
python3 -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest