SQL#

The SQL module provides a SQL-based version of the DBContextStorage class. This class is used to store and retrieve context data from SQL databases. It allows Chatsky to easily store and retrieve context data in a format that is highly scalable and easy to work with.

The SQL module provides the ability to choose the backend of your choice from MySQL, PostgreSQL, or SQLite. You can choose the one that is most suitable for your use case and environment. MySQL and PostgreSQL are widely used open-source relational databases that are known for their reliability and scalability. SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain, SQL database engine.

import_insert_for_dialect(dialect)[source]#

Imports the insert function into global scope depending on the chosen sqlalchemy dialect.

Parameters:

dialect (str) – Chosen sqlalchemy dialect.

class SQLContextStorage(path, table_name='contexts', custom_driver=False)[source]#

Bases: DBContextStorage

SQL-based version of the DBContextStorage.
Compatible with MySQL, Postgresql, Sqlite.
Parameters:
  • path (str) – Standard sqlalchemy URI string. When using sqlite backend in Windows, keep in mind that you have to use double backslashes ‘' instead of forward slashes ‘/’ in the file path.

  • table_name (str) – The name of the table to use.

  • custom_driver (bool) – If you intend to use some other database driver instead of the recommended ones, set this parameter to True to bypass the import checks.

set_item_async(key, value)[source]#

Asynchronous method for storing Context.

Parameters:
  • key (Hashable) – Hashable key used to store Context instance.

  • value (Context) – Context to store.

get_item_async(key)[source]#

Asynchronous method for accessing stored Context.

Parameters:

key (Hashable) – Hashable key used to store Context instance.

Return type:

Context

Returns:

The stored context, associated with the given key.

del_item_async(key)[source]#

Asynchronous method for removing stored Context.

Parameters:

key (Hashable) – Hashable key used to identify Context instance for deletion.

contains_async(key)[source]#

Asynchronous method for finding whether any Context is stored with given key.

Parameters:

key (Hashable) – Hashable key used to check if Context instance is stored.

Return type:

bool

Returns:

True if there is Context accessible by given key, False otherwise.

len_async()[source]#

Asynchronous method for retrieving number of stored Contexts.

Return type:

int

Returns:

The number of stored Contexts.

clear_async()[source]#

Asynchronous method for clearing context storage, removing all the stored Contexts.

async _create_self_table()[source]#
async _get_update_stmt(insert_stmt)[source]#
_check_availability(custom_driver)[source]#