module sql.magic_sql

Inheritance diagram of pyensae.sql.magic_sql

Short summary

module pyensae.sql.magic_sql

Defines SQL commands to play with sqlite3. See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

Classes

class

truncated documentation

MagicSQL

Defines SQL commands to play with sqlite3 See notebook SQL Magic Commands with SQLite in a Notebook. …

Functions

function

truncated documentation

register_sql_magics

register magics function, can be called from a notebook

Properties

property

truncated documentation

Context

return the context or None

cross_validation_lock

A contextmanager for running a block with our cross validation lock set to True. At the end of the block, …

Static Methods

staticmethod

truncated documentation

SQL_add_function_parser

defines the way to parse the magic command %SQL_add_function

SQL_close_parser

defines the way to parse the magic command %SQL_close

SQL_connect_parser

defines the way to parse the magic command %SQL_connect

SQL_drop_table_parser

defines the way to parse the magic command %SQL_drop_table

SQL_import_df_parser

defines the way to parse the magic command %SQL_import_df

SQL_import_tsv_parser

defines the way to parse the magic command %SQL_import_tsv

SQL_parser

defines the way to parse the magic command %%SQL

SQL_refresh_completion_parser

defines the way to parse the magic command %SQL_refresh_completion

SQL_schema_parser

defines the way to parse the magic command %SQL_schema

SQL_tables_parser

defines the way to parse the magic command %SQL_tables

Methods

method

truncated documentation

get_connection

returns the connection stored in the workspace

SQL

defines command %%SQL

SQL_add_function

defines %SQL_add_function which adds a function to the database

SQL_close

define SQL_close which closes a database

SQL_connect

define SQL_connect which connects to a SQL database, it stores the database object in variable DB by default …

SQL_drop_table

defines %SQL_drop_table which drops a table from a database

SQL_import_df

defines %SQL_import_df which imports a dataframe into a database

SQL_import_tsv

defines %SQL_import_tsv whichs import a TSV file into a database

SQL_refresh_completion

defines %SQL_refresh_completion

SQL_schema

define SQL_schema

SQL_tables

define %SQL_tables whichs lists the tables in a database

Documentation

Defines SQL commands to play with sqlite3. See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

class pyensae.sql.magic_sql.MagicSQL(**kwargs: Any)

Bases: MagicClassWithHelpers

Defines SQL commands to play with sqlite3 See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

Create a configurable given a config config.

Parameters

configConfig

If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

parentConfigurable instance, optional

The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__() method of Configurable before doing anything else and using super():

class MyConfigurable(Configurable):
    def __init__(self, config=None):
        super(MyConfigurable, self).__init__(config=config)
        # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.

SQL(line, cell=None)

defines command %%SQL

SQL

The code for magic command %%SQL is equivalent to:

<variable> = db.execute(<cell>)

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

SQL_add_function(line)

defines %SQL_add_function which adds a function to the database

SQL_add_function

The code for magic command %SQL_add_function is equivalent to:

db.add_function(fu)

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_add_function_parser()

defines the way to parse the magic command %SQL_add_function

source on GitHub

SQL_close(line='')

define SQL_close which closes a database

SQL_close

The code for magic command %SQL_close is equivalent to:

db.close()

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_close_parser()

defines the way to parse the magic command %SQL_close

source on GitHub

SQL_connect(line)

define SQL_connect which connects to a SQL database, it stores the database object in variable DB by default

SQL_connect_parser

The code for magic command %SQL_connect_parser is equivalent to:

from pyense.sql import InterfaceSQL
obj = InterfaceSQL.create(args.filename)
obj.connect()

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_connect_parser()

defines the way to parse the magic command %SQL_connect

source on GitHub

SQL_drop_table(line)

defines %SQL_drop_table which drops a table from a database

SQL_drop_table

The code for magic command %SQL_drop_table is equivalent to:

db.drop_table()

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_drop_table_parser()

defines the way to parse the magic command %SQL_drop_table

source on GitHub

SQL_import_df(line)

defines %SQL_import_df which imports a dataframe into a database

SQL_import_df

The code for magic command %SQL_import_df is equivalent to:

db.import_dataframe(<table>, <df>)

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_import_df_parser()

defines the way to parse the magic command %SQL_import_df

source on GitHub

SQL_import_tsv(line)

defines %SQL_import_tsv whichs import a TSV file into a database

SQL_import_tsv

The code for magic command %SQL_import_tsv is equivalent to:

db.import_flat_file(<filename>, <table>)

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_import_tsv_parser()

defines the way to parse the magic command %SQL_import_tsv

source on GitHub

static SQL_parser()

defines the way to parse the magic command %%SQL

source on GitHub

SQL_refresh_completion(line='')

defines %SQL_refresh_completion

source on GitHub

static SQL_refresh_completion_parser()

defines the way to parse the magic command %SQL_refresh_completion

source on GitHub

SQL_schema(line='')

define SQL_schema

SQL_schema

The code for magic command %SQL_schema is equivalent to:

db.get_table_columns(<table>, as_dict=not <as_list>)

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_schema_parser()

defines the way to parse the magic command %SQL_schema

source on GitHub

SQL_tables(line='')

define %SQL_tables whichs lists the tables in a database

SQL_tables

The code for magic command %SQL_tables is equivalent to:

db.get_table_list()

See notebook SQL Magic Commands with SQLite in a Notebook.

source on GitHub

static SQL_tables_parser()

defines the way to parse the magic command %SQL_tables

source on GitHub

_all_trait_default_generators: Dict[str, Any] = {'config': <bound method TraitType.default of <traitlets.traitlets.Instance object>>, 'parent': <bound method TraitType.default of <traitlets.traitlets.Instance object>>}
_cross_validation_lock: bool
_descriptors = [<traitlets.traitlets.ObserveHandler object>, <traitlets.traitlets.Instance object>, <traitlets.traitlets.Instance object>]
_instance_inits = [<bound method ObserveHandler.instance_init of <traitlets.traitlets.ObserveHandler object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>, <bound method Instance.instance_init of <traitlets.traitlets.Instance object>>]
_static_immutable_initial_values: Dict[str, Any] = {'parent': None}
_trait_default_generators = {}
_trait_notifiers: Dict[str, Any]
_trait_validators: Dict[str, Any]
_trait_values: Dict[str, Any]
_traits: Dict[str, Any] = {'config': <traitlets.traitlets.Instance object>, 'parent': <traitlets.traitlets.Instance object>}
get_connection(name)

returns the connection stored in the workspace

Parameters:

name – variable name of the database

Returns:

object

source on GitHub

pyensae.sql.magic_sql.register_sql_magics(ip=None)

register magics function, can be called from a notebook

Parameters:

ip – from get_ipython()

source on GitHub