langchain_community.utilities.cassandra_database.CassandraDatabase¶

class langchain_community.utilities.cassandra_database.CassandraDatabase(session: Optional[Session] = None, exclude_tables: Optional[List[str]] = None, include_tables: Optional[List[str]] = None, cassio_init_kwargs: Optional[Dict[str, Any]] = None)[source]¶

Apache Cassandra® database wrapper.

Methods

__init__([session, exclude_tables, ...])

fetch_all(query, **kwargs)

fetch_one(query, **kwargs)

format_keyspace_to_markdown(keyspace[, tables])

Generates a markdown representation of the schema for a specific keyspace by iterating over all tables within that keyspace and calling their as_markdown method.

format_schema_to_markdown()

Generates a markdown representation of the schema for all keyspaces and tables within the CassandraDatabase instance.

get_context()

Return db context that you may want in agent prompt.

get_keyspace_tables(keyspace)

Get the Table objects for the specified keyspace.

get_table_data(keyspace, table, predicate, limit)

Get data from the specified table in the specified keyspace.

run(query[, fetch])

Execute a CQL query and return the results.

Parameters
  • session (Optional[Session]) –

  • exclude_tables (Optional[List[str]]) –

  • include_tables (Optional[List[str]]) –

  • cassio_init_kwargs (Optional[Dict[str, Any]]) –

__init__(session: Optional[Session] = None, exclude_tables: Optional[List[str]] = None, include_tables: Optional[List[str]] = None, cassio_init_kwargs: Optional[Dict[str, Any]] = None)[source]¶
Parameters
  • session (Optional[Session]) –

  • exclude_tables (Optional[List[str]]) –

  • include_tables (Optional[List[str]]) –

  • cassio_init_kwargs (Optional[Dict[str, Any]]) –

fetch_all(query: str, **kwargs: Any) list[source]¶
Parameters
  • query (str) –

  • kwargs (Any) –

Return type

list

fetch_one(query: str, **kwargs: Any) Dict[str, Any][source]¶
Parameters
  • query (str) –

  • kwargs (Any) –

Return type

Dict[str, Any]

format_keyspace_to_markdown(keyspace: str, tables: Optional[List[Table]] = None) str[source]¶

Generates a markdown representation of the schema for a specific keyspace by iterating over all tables within that keyspace and calling their as_markdown method.

Parameters
  • keyspace (str) – The name of the keyspace to generate markdown documentation for.

  • tables (Optional[List[Table]]) – list of tables in the keyspace; it will be resolved if not provided.

Returns

A string containing the markdown representation of the specified keyspace schema.

Return type

str

format_schema_to_markdown() str[source]¶

Generates a markdown representation of the schema for all keyspaces and tables within the CassandraDatabase instance. This method utilizes the format_keyspace_to_markdown method to create markdown sections for each keyspace, assembling them into a comprehensive schema document.

Iterates through each keyspace in the database, utilizing format_keyspace_to_markdown to generate markdown for each keyspace’s schema, including details of its tables. These sections are concatenated to form a single markdown document that represents the schema of the entire database or the subset of keyspaces that have been resolved in this instance.

Returns

A markdown string that documents the schema of all resolved keyspaces and their tables within this CassandraDatabase instance. This includes keyspace names, table names, comments, columns, partition keys, clustering keys, and indexes for each table.

Return type

str

get_context() Dict[str, Any][source]¶

Return db context that you may want in agent prompt.

Return type

Dict[str, Any]

get_keyspace_tables(keyspace: str) List[Table][source]¶

Get the Table objects for the specified keyspace.

Parameters

keyspace (str) –

Return type

List[Table]

get_table_data(keyspace: str, table: str, predicate: str, limit: int) str[source]¶

Get data from the specified table in the specified keyspace.

Parameters
  • keyspace (str) –

  • table (str) –

  • predicate (str) –

  • limit (int) –

Return type

str

run(query: str, fetch: str = 'all', **kwargs: Any) Union[list, Dict[str, Any], ResultSet][source]¶

Execute a CQL query and return the results.

Parameters
  • query (str) –

  • fetch (str) –

  • kwargs (Any) –

Return type

Union[list, Dict[str, Any], ResultSet]