Skip to content

SQLAlchemy Backend Base Classes

BaseAlchemyBackend

Bases: BaseSQLBackend

Backend class for backends that compile to SQLAlchemy expressions.

Attributes

current_database: str property

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

Functions

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

Create a table.

Parameters:

Name Type Description Default
name str

Table name to create

required
expr pd.DataFrame | ir.Table | None

DataFrame or table expression to use as the data source

None
schema sch.Schema | None

An ibis schema

None
database str | None

A database

None
force bool

Check whether a table exists before creating it

False

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

Drop a table.

Parameters:

Name Type Description Default
table_name str

Table to drop

required
database str | None

Database to drop table from

None
force bool

Check for existence before dropping

False

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

Insert data into a table.

Parameters:

Name Type Description Default
table_name str

The name of the table to which data needs will be inserted

required
obj pd.DataFrame | ir.Table | list | dict

The source data or expression to insert

required
database str | None

Name of the attached database that the table is located in.

None
overwrite bool

If True then replace existing contents of table

False

Raises:

Type Description
NotImplementedError

If inserting data from a different database

ValueError

If the type of obj isn't supported

list_databases(like=None)

List databases in the current server.

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

Load data from a dataframe to the backend.

Parameters:

Name Type Description Default
table_name str

Name of the table in which to load data

required
data pd.DataFrame

Pandas DataFrame

required
database str | None

Database in which the table exists

None
if_exists Literal['fail', 'replace', 'append']

What to do when data in name already exists

'fail'

Raises:

Type Description
NotImplementedError

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

schema(name)

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

Parameters:

Name Type Description Default
name str

Table name

required

Returns:

Type Description
Schema

The ibis schema of name

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

Create a table expression from a table in the database.

Parameters:

Name Type Description Default
name str

Table name

required
database str | None

The database the table resides in

None
schema str | None

The schema inside database where the table resides.

schema refers to database organization

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

None

Returns:

Type Description
Table

Table expression


Last update: January 4, 2023