Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Way to define your own magic function.

## [0.5.0] - 2021-05-22

Expand Down
17 changes: 15 additions & 2 deletions noteql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

LOCAL_DB_MADE = False

REGISTERED_MAGICS = False


def get_engine(dburi):
if not dburi:
Expand Down Expand Up @@ -110,7 +112,8 @@ def __init__(
df_viewer=None,
df_viewer_kw=None,
datasette_url=None,
cell_magic_output=False
cell_magic_name=None,
cell_magic_output=False,
):
self.schema = schema
self.dburi = dburi
Expand Down Expand Up @@ -150,7 +153,17 @@ def __init__(
connection.execute("create schema if not exists {};".format(self.schema))

self.ipython = get_ipython()
self.ipython.register_magics(Noteql)

global REGISTERED_MAGICS

if not REGISTERED_MAGICS:
if cell_magic_name:
Noteql.magics["line"][cell_magic_name] = Noteql.magics["line"].pop("nql")
Noteql.magics["cell"][cell_magic_name] = Noteql.magics["cell"].pop("nql")

self.ipython.register_magics(Noteql)
REGISTERED_MAGICS = True

self.set()

def tables(self):
Expand Down