OLTPConnection#

class swordfish.connection.OLTPConnection(impl)#

Manages connections to OLTP databases.

示例

>>> import swordfish as sf
>>> conn = sf.connect(url="/path/to/file")
create_table(name, types, primary, secondary=None)#

Creates a new table in the database.

参数:
  • name (str) -- The name of the table to create.

  • types (TypeDict) -- A dictionary specifying the column names and their data types.

  • primary (list of str or str) -- The primary key of the table.

  • secondary (list of tuple, optional) -- Secondary indexes or constraints for the table. Defaults to None.

返回:

A new table created based on the given parameters.

返回类型:

Table

示例

>>> conn.create_table("table_name", {
...     'a': "INT",
...     'b': "INT",
...     'c': "BOOL",
...     'd': "LONG",
...     'e': "STRING",
... }, "a", [[True, ["b", "c", "d"]], [False, ["d"]]])
drop_table(name)#

Drops a table from the database.

参数:

name (str) -- The name of the table to drop.

示例

>>> conn.drop_table("table_name")
list_tables()#

Retrieves the names of all tables in the database.

返回:

A list of table names in the database.

返回类型:

list

示例

>>> conn.list_tables()
exists_table(name)#
参数:

name (str)

返回类型:

bool

table(name)#

Retrieves a specific table from the database.

参数:

name (str) -- The name of the table.

返回:

The corresponding table object.

返回类型:

Table

示例

>>> t = conn.table("table_name")