SQLTable#

class dbastable.SQLTable(db, name)#

Bases: object

Handle an SQL table operations interfacing with the DB.

Parameters:
dbSQLDatabase

The parent database object.

namestr

The name of the table in the database.

Attributes Summary

column_names

Get the column names of the current table.

db

Get the database name.

name

Get the name of the table.

values

Get the values of the current table.

Methods Summary

add_column(name[, data])

Add a column to the table.

add_rows(data[, add_columns])

Add a row to the table.

as_table()

Return the current table as an Table object.

delete_column(column)

Delete a given column from the table.

delete_row(row)

Delete all rows from the table.

get_column(column)

Get a given column from the table.

get_row(row)

Get a given row from the table.

index_of(where)

Get the index of the rows that match the given condition.

select(**kwargs)

Select rows from the table.

set_column(column, data)

Set a given column in the table.

set_row(row, data)

Set a given row in the table.

Attributes Documentation

column_names#

Get the column names of the current table.

db#

Get the database name.

name#

Get the name of the table.

values#

Get the values of the current table.

Methods Documentation

add_column(name, data=None)#

Add a column to the table. See add_column.

Parameters:
namestr

Column name.

datalist (optional)
add_rows(data, add_columns=False)#

Add a row to the table. See add_rows.

Parameters:
datadict, list or ndarray

Data to add to the table. If dict, keys are column names, if list, the order of the values is the same as the order of the column names. If ndarray, dtype names are interpreted as column names.

add_columnsbool (optional)

If True, add missing columns to the table.

as_table()#

Return the current table as an Table object.

delete_column(column)#

Delete a given column from the table. See delete_column.

Parameters:
columnstr

Column name.

delete_row(row)#

Delete all rows from the table. See delete_row.

Parameters:
rowint

Row index.

get_column(column)#

Get a given column from the table. See get_column.

Parameters:
columnstr

Column name.

Returns:
resSQLColumn

Column viewer object.

get_row(row)#

Get a given row from the table. See get_row.

Parameters:
rowint

Row index.

Returns:
resSQLRow

Row viewer object.

index_of(where)#

Get the index of the rows that match the given condition. See index_of.

Parameters:
wheredict

Dictionary of conditions to select rows. Keys are column names, values are values to compare. If it is a dict of values, all rows equal to the values will be selected. If it is a dict of Where objects, the conditions will be combined with the AND operator. If None, all rows are selected.

Returns:
reslist

List of row indexes.

select(**kwargs)#

Select rows from the table. See select.

Parameters:
columnslist (optional)

List of columns to select. If None, select all columns.

wheredict (optional)

Dictionary of conditions to select rows. Keys are column names, values are values to compare. If it is a dict of values, all rows equal to the values will be selected. If it is a dict of Where objects, the conditions will be combined with the AND operator. If None, all rows are selected.

orderstr (optional)

Column name to order by.

limitint (optional)

Number of rows to select.

offsetint (optional)

Number of rows to skip before selecting.

Returns:
reslist

List of tuples with the selected rows. Each row values will be returned in a tuple in the same order as the columns.

set_column(column, data)#

Set a given column in the table. See set_column.

Parameters:
columnstr

Column name.

datalist

List of values to set.

set_row(row, data)#

Set a given row in the table. See set_row.

Parameters:
rowint

Row index.

datadict, list or ndarray

Data to add to the table. If dict, keys are column names, if list, the order of the values is the same as the order of the column names. If ndarray, dtype names are interpreted as column names.