InsertDatabaseOption#

class teamworksams.database_option.InsertDatabaseOption(table_fields: List[str] | None = None, interactive_mode: bool = True, cache: bool = True)[source]#

Bases: object

Options for inserting database entries into an AMS database form.

Customizes the behavior of insert_database_entry(), controlling table fields, caching, and interactive feedback. These options tailor the insertion process for one-off operations, ensuring data aligns with the AMS form’s structure. See Database Operations for database workflows.

Parameters:
  • table_fields (Optional[List[str]]) – List of field names in the AMS form that are table fields (e.g., [‘Table’]). Must match pandas.DataFrame columns if specified. If None, no fields are treated as table fields. Defaults to None.

  • interactive_mode (bool) – If True, prints status messages during execution, such as “Inserted 3 entries,” ideal for interactive environments. Set to False for silent execution. Defaults to True.

  • cache (bool) – If True, reuses cached API responses via the AMSClient, reducing API calls for repeated operations. Set to False for independent requests. Defaults to True.

table_fields#

List of table field names, or None if unspecified.

Type:

Optional[List[str]]

interactive_mode#

Whether interactive mode is enabled.

Type:

bool

cache#

Whether caching is enabled.

Type:

bool

Examples

>>> from teamworksams import InsertDatabaseOption, insert_database_entry
>>> import pandas as pd
>>> df = pd.DataFrame({"Allergy": ["Dairy"]})
>>> option = InsertDatabaseOption(interactive_mode = True)
>>> insert_database_entry(
...     df = df,
...     form = "Allergies",
...     url = "https://example.smartabase.com/site",
...     option = option
... )
ℹ Inserting 1 database entries for form 'Allergies'
✔ Processed 1 database entries for form 'Allergies'
__init__(table_fields: List[str] | None = None, interactive_mode: bool = True, cache: bool = True)[source]#

Additional Notes#

  • Specify table_fields for AMS forms with table data (e.g., [‘Table’]), ensuring column names in the pandas.DataFrame match exactly to avoid AMSError.

  • Enable interactive_mode=True for feedback like “Inserted 3 entries,” ideal for one-off insertions in interactive scripts.

  • Use cache=True to optimize performance when inserting multiple entries in a single session.

See Also#