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, obj=None, *, schema=None, database=None, temp=False, overwrite=False)

Create a table.

Parameters:

Name Type Description Default
name str

Name of the new table.

required
obj pd.DataFrame | ir.Table | None

An Ibis table expression or pandas table that will be used to extract the schema and the data of the new table. If not provided, schema must be given.

None
schema sch.Schema | None

The schema for the new table. Only one of schema or obj can be provided.

None
database str | None

Name of the database where the table will be created, if not the default.

None
temp bool

Should the table be temporary for the session.

False
overwrite bool

Clobber existing data

False

Returns:

Type Description
Table

The table that was created.

drop_table(name, *, database=None, force=False)

Drop a table.

Parameters:

Name Type Description Default
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

raw_sql(query)

Execute a query string.

The returned cursor object must be manually released.

Parameters:

Name Type Description Default
query

DDL or DML statement

required

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