Skip to content

orcalib.table#

TableHandle #

TableHandle(db_name, table_name, _columns=None)

A handle to a table in the Orca database

Parameters:

  • db_name (str) –

    The database name

  • table_name (str) –

    The table name

get_column_type_dict #

get_column_type_dict()

Get a dictionary of column names and orca types for this table

Returns:

Examples:

>>> table.get_column_type_dict()
{ 'id': IntT, 'str': TextT, 'img': ImageT["PNG"], 'vec': VectorT[64] }

copy #

copy()

Create a copy of this table handle

Returns:

__getattr__ #

__getattr__(column_name)

Get a column handle by name

Parameters:

Returns:

__getitem__ #

__getitem__(column_name)

Get a column handle by name

Parameters:

Returns:

get_column #

get_column(column_name)

Get a column handle by name

Parameters:

Returns:

select #

select(*args)

Start a new query on this table

Parameters:

Returns:

Examples:

>>> table.select('id', 'name').where(table.tester = 1).fetch(2)
[{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]

where #

where(*args)

Start a new query on this table

Parameters:

  • *args (OrcaExpr, default: () ) –

    Query filter

Returns:

order_by #

order_by(*args, **kwargs)

Start a new query on this table

Parameters:

  • *args (str | ColumnHandle, default: () ) –

    The columns to order by

  • **kwargs (Order | Literal['ASC', 'DESC'], default: {} ) –

    Order direction

Returns:

fetch #

fetch(limit=None, include_ids=False)

Fetch rows from the table

Parameters:

  • limit (int | None, default: None ) –

    The maximum number of rows to return

  • include_ids (bool, default: False ) –

    Whether to include the row ids in the result

Returns:

df #

df(limit=None)

Fetch rows from the table and return as a pandas DataFrame

Parameters:

  • limit (int | None, default: None ) –

    The maximum number of rows to fetch (default: None)

Returns:

insert #

insert(*args, **kwargs)

Insert rows into the table

Note

Positional and keyword arguments cannot be mixed.

Parameters:

  • *args (RowData, default: () ) –

    The row data to insert. This can be a RowDict, a pandas DataFrame, or a list of RowDicts.

  • **kwargs (Any, default: {} ) –

    Specifies the keys and values to insert. This can be used to insert a single row.

Examples:

Insert a single row as a dict:

>>> table.insert({'id': 1, 'name': 'Alice'})

Insert multiple rows as multiple arguments:

>>> table.insert({'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'})

Insert multiple rows as a list of dicts:

>>> table.insert([{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}])

Insert multiple rows as a pandas DataFrame:

>>> table.insert(pd.DataFrame({'id': [1, 2], 'name': ['Alice', 'Bob']}))

Insert a single row as keyword arguments:

>>> table.insert(id=1, name='Alice')

update #

update(data, filter)

Update rows in the table

Parameters:

  • data (RowDict) –

    The row data to update. This should be a dict[str, Any] where the keys are column names.

  • filter (OrcaExpr) –

    The filter to apply to the rows to update

Examples:

>>> table.update([{'name': 'Alice'}], table.id == 1)

upsert #

upsert(data, key_columns)

Upsert rows into the table

Parameters:

  • data (RowData) –

    The row data to insert.

  • key_columns (list[ColumnName]) –

    The columns to use as the primary key

Examples:

>>> table.upsert({'id': 1, 'name': 'Alice'}, ['id'])

delete #

delete(filter)

Delete rows from the table

Parameters:

  • filter (OrcaExpr) –

    The filter to apply to the rows to delete

Examples:

>>> table.delete(table.id == 1)

count #

count()

Count the number of rows in the table

Returns:

  • int

    The number of rows in the table

add_column #

add_column(**columns)

Add columns to the table

Parameters:

Examples:

>>> table.add_column(test=TextT.notnull, img=ImageT["PNG"])

drop_column #

drop_column(*column_names)

Drop columns from the table

Parameters:

  • column_names (str, default: () ) –

    The column or columns to drop

Examples:

>>> table.drop_column('test')
>>> table.drop_column(['test', 'img'])