Skip to content

SQLAlchemy Backend Base Classes

BaseAlchemyBackend (BaseSQLBackend)

Backend class for backends that compile to SQLAlchemy expressions.

Attributes

current_database: str property readonly

The name of the current database this client is connected to.

version property readonly

Return the version of the backend engine.

For database servers, return the server version.

For others such as SQLite and pandas return the version of the underlying library or application.

Returns

str The backend version

Methods

create_table(self, name, expr=None, schema=None, database=None, force=False)

Create a table.

Parameters

name Table name to create expr DataFrame or table expression to use as the data source schema An ibis schema database A database force Check whether a table exists before creating it

drop_table(self, table_name, database=None, force=False)

Drop a table.

Parameters

table_name Table to drop database Database to drop table from force Check for existence before dropping

insert(self, table_name, obj, database=None, overwrite=False)

Insert data into a table.

Parameters

table_name The name of the table to which data needs will be inserted obj The source data or expression to insert database Name of the attached database that the table is located in. overwrite If True then replace existing contents of table

Raises

NotImplementedError If inserting data from a different database ValueError If the type of obj isn't supported

list_databases(self, like=None)

List databases in the current server.

list_schemas(self, like=None)

DEPRECATED: list_schemas is deprecated as of v2.0; use list_databases

list_tables(self, like=None, database=None)

Return the list of table names in the current database.

For some backends, the tables may be files in a directory, or other equivalent entities in a SQL database.

Parameters

like : str, optional A pattern in Python's regex format. database : str, optional The database to list tables of, if not the current one.

Returns

list[str] The list of the table names that match the pattern like.

load_data(self, table_name, data, database=None, if_exists='fail')

Load data from a dataframe to the backend.

Parameters

table_name Name of the table in which to load data data Pandas DataFrame database Database in which the table exists if_exists What to do when data in name already exists

Raises

NotImplementedError Loading data to a table from a different database is not yet implemented

schema(self, name)

Get an ibis schema from the current database for the table name.

Parameters

name Table name

Returns

Schema The ibis schema of name

table(self, name, database=None, schema=None)

Create a table expression from a table in the database.

Parameters

name Table name database The database the table resides in schema The schema inside database where the table resides.

!!! warning "`schema` refers to database organization"

    The `schema` parameter does **not** refer to the column names
    and types of `table`.
Returns

Table Table expression


Last update: March 1, 2022