thanosql.resources._table

Module Contents

Classes

BaseColumn

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

Column

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

Unique

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

PrimaryKey

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

ForeignKey

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

Constraints

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

BaseTable

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

TableObject

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

IfExists

Create a collection of name/value pairs.

TableService

Service layer for table methods.

OnConflict

Create a collection of name/value pairs.

Table

Extends the BaseTable class, which has name, schema,

TableTemplate

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

TableTemplateService

Service layer for table template methods.

class thanosql.resources._table.BaseColumn(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

default: str | None
is_nullable: bool | None = True
type: str
name: str
class thanosql.resources._table.Column(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

id: int | None
default: str | None
is_nullable: bool | None = True
type: str
name: str
class thanosql.resources._table.Unique(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

name: str | None
columns: List[str] | None = []
class thanosql.resources._table.PrimaryKey(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

name: str | None
columns: List[str] | None = []
class thanosql.resources._table.ForeignKey(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

name: str | None
reference_schema: str = 'public'
reference_column: str
reference_table: str
column: str
class thanosql.resources._table.Constraints(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

unique: List[Unique] | None
primary_key: PrimaryKey | None
foreign_keys: List[ForeignKey] | None
class thanosql.resources._table.BaseTable(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

name: str | None
table_schema: str | None
columns: List[BaseColumn] | None
constraints: Constraints | None
class thanosql.resources._table.TableObject(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

columns: List[BaseColumn] | None
constraints: Constraints | None
class thanosql.resources._table.IfExists(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

FAIL = 'fail'
APPEND = 'append'
REPLACE = 'replace'
class thanosql.resources._table.TableService(client: thanosql._client.ThanoSQL)[source]

Bases: thanosql._service.ThanoSQLService

Service layer for table methods.

client

The ThanoSQL client used to make requests to the engine.

Type:

ThanoSQL

template

The table template service layer to access methods involving table templates.

Type:

TableTemplateService

list(schema: str | None = None, verbose: bool | None = None, offset: int | None = None, limit: int | None = None) List[Table][source]

Lists tables stored in the workspace.

Parameters:
  • schema (str, optional) – The schema where the listed tables should reside in. If not set, all tables from all schemas will be included.

  • verbose (bool, optional) – Whether to include the table columns and constraints in the results. By default, or if set to False, only retrieves the names and schemas of stored tables.

  • offset (int, optional) – When set to n, skips the first n results and excludes them from the output list. Otherwise, starts the list from the first result stored. Must be greater than 0.

  • limit (int, optional) – When set to n, limits the number of results listed to n. Otherwise, lists up to 100 results per call. Must range between 0 to 100.

Returns:

A list of Table objects.

Return type:

List[Table]

Raises:

ThanoSQLValueError – If offset is less than 0 or if limit is not between 0 to 100 (inclusive).

get(name: str, schema: str | None = None) Table[source]

Shows the details of the specified table.

Parameters:
  • name (str) – The name of the table to be retrieved.

  • schema (str, optional) – The schema where the table to be retrieved is in. If not specified, this method will look for the table in “public”.

Returns:

A Table object.

Return type:

Table

update(name: str, schema: str | None = None, table: BaseTable | None = None) Table[source]

Updates the specified table.

Parameters:
  • name (str) – The name of the table to be updated.

  • schema (str, optional) – The schema where the table to be updated is in. If not specified, this method will look for the table in “public”.

  • table (BaseTable, optional) –

    BaseTable object containing changed details of the table to be updated. Any attribute of BaseTable can be modified, and if left unset, the current value will be maintained after update. The attributes are as follows:

    • name: new name to rename the table to

    • schema: new schema to move the table to

    • columns: new columns of the updated table. All new columns must be in this object, including columns that already exist in the original table. If this attribute is set but some original columns are not included, they will be removed from the table.

    • constraints: new constraints of the updated table. All new constraints must be in this object, including constraints that already exist in the original table. If this attribute is set but some original constraints are not included, they will be removed from the table.

Returns:

Table object of the new table after update.

Return type:

Table

Raises:

ThanoSQLValueError – If the table object contains invalid formatting.

create(name: str, table: TableObject, schema: str | None = None, if_not_exists: bool = False) Table[source]

Creates a new table.

Parameters:
  • name (str) – The name of the table to be created.

  • table (TableObject) – TableObject containing the columns and constraints of the table to be created. In order to create an empty table, pass in an empty object (TableObject()).

  • schema (str, optional) – The schema to save the created table in. If not specified, the table will be saved to “public”.

  • if_not_exists (bool, default False) – Whether to throw an error if a table of the same name already exists. When set to False (default), an error will be shown. When True, the table will only be created if it does not exist already. Otherwise, do nothing.

Returns:

Table object of the created table.

Return type:

Table

Raises:

ThanoSQLValueError – If the table object contains invalid formatting.

upload(name: str, file: str | os.PathLike | None = None, df: pandas.DataFrame | None = None, schema: str | None = None, table: TableObject | None = None, if_exists: str = 'fail') Table[source]

Uploads the contents of a CSV or Excel-like file or Pandas DataFrame into the specified table.

Either a CSV or Excel-like (.xls, .xlsx, .xlsm, .xlsb, .odf, .ods, .odt) file or DataFrame must be specified. However, both should not be used at the same time.

Note: If you are working with a Strict Open XML Spreadsheet (.xlsx) file, change it to Excel Workbook (.xlsx), save it, and try using it again.

Parameters:
  • name (str) – The name of the table created from the file or DataFrame.

  • file (str or PathLike, optional) – CSV or Excel-like file containing tabulated data to be uploaded to the specified table.

  • df (DataFrame, optional) – Pandas DataFrame containing data to be uploaded to the specified table.

  • schema (str, optional) – The schema to save the created table in. If not specified, the table will be saved to “public”.

  • table (TableObject, optional) – TableObject containing the columns and constraints of the table to be created. If specified, the created table will follow the object format and no type inference is conducted. Otherwise, type inference will be performed and the table will be created to match the columns from source.

  • if_exists (str, default "fail") –

    What to do if table of the same name already exists. There are only three available values:

    • fail: fails (throws an error) if the same table exists

    • append: appends records into an existing table (columns must match in order to not make an error)

    • replace: deletes existing table and creates a new one with the given name

Returns:

Table object of the uploaded table.

Return type:

Table

Raises:

ThanoSQLValueError

  • If if_exists is not one of “fail”, “append”, or “replace”.

  • If neither file nor df is used, or if both are used at the same time.

  • If file is used but it is neither CSV nor Excel-like.

  • If the file or df contains badly-formatted contents.

  • If a table body is specified but does not match the contents of the file or df.

  • If if_exists is set to “append” but the new contents does not match the format of the existing table.

delete(name: str, schema: str | None = None) dict[source]

Deletes the specified table.

Parameters:
  • name (str) – The name of the table to be deleted.

  • schema (str, optional) – The schema where the table to be deleted is in. If not specified, this method will look for the table in “public”.

Returns:

A dictionary containing a success message, table name, and schema in the format of:

{
    "message": "string",
    "table_name": "string",
    "schema": "string"
}

Return type:

dict

class thanosql.resources._table.OnConflict(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

FAIL = 'fail'
SKIP = 'skip'
class thanosql.resources._table.Table(/, **data: Any)[source]

Bases: BaseTable

Extends the BaseTable class, which has name, schema, columns, and constraints as attributes, with a table service layer to allow connection to the ThanoSQL engine.

service: TableService | None

The table service layer to access the ThanoSQL client.

get_records(offset: int | None = None, limit: int | None = None) thanosql.resources._record.Records[source]

Lists the records of the table.

Parameters:
  • offset (int, optional) – When set to n, skips the first n results and excludes them from the output list. Otherwise, starts the list from the first result stored. Must be greater than 0.

  • limit (int, optional) – When set to n, limits the number of results listed to n. Otherwise, lists up to 100 results per call. Must range between 0 to 100.

Returns:

A Records object.

Return type:

Records

Raises:

ThanoSQLValueError – If offset is less than 0 or if limit is not between 0 to 100 (inclusive).

get_records_as_csv(timezone_offset: int | None = None) None[source]

Downloads the records of the table as a CSV file.

Parameters:

timezone_offset (int, optional) – Timezone offset from Coordinated Universal Time (UTC). If not set, this value is 9, following the timezone in Seoul. This value is used to determine the time used in the file name.

insert(records: List[dict], on_conflict: str = 'fail') Table[source]

Inserts records to the specified table.

Parameters:
  • records (list of dict) – The records to be inserted in the format of a list of column-value pairs.

  • on_conflict (str, default "fail") –

    What to do when conflict(s) due to unique constraint violation happen(s). There are only two available values:

    • fail: fails (throws an error) if any of the record violates the target table’s unique constraint(s)

    • skip: skips record(s) that violate(s) unique constraint(s) and insert the rest

Returns:

A Table object.

Return type:

Table

Raises:

ThanoSQLValueError

  • If on_conflict is not one of “fail” or “skip”.

  • If the records are in an invalid format or contain invalid contents.

class thanosql.resources._table.TableTemplate(/, **data: Any)[source]

Bases: thanosql.resources._model.BaseModel

Usage docs: https://docs.pydantic.dev/2.9/concepts/models/

A base class for creating Pydantic models.

__class_vars__

The names of the class variables defined on the model.

__private_attributes__

Metadata about the private attributes of the model.

__signature__

The synthesized __init__ [Signature][inspect.Signature] of the model.

__pydantic_complete__

Whether model building is completed, or if there are still undefined fields.

__pydantic_core_schema__

The core schema of the model.

__pydantic_custom_init__

Whether the model has a custom __init__ function.

__pydantic_decorators__

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_generic_metadata__

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__

The name of the post-init method for the model, if defined.

__pydantic_root_model__

Whether the model is a [RootModel][pydantic.root_model.RootModel].

__pydantic_serializer__

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__

The pydantic-core SchemaValidator used to validate instances of the model.

__pydantic_extra__

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields_set__

The names of fields explicitly set during instantiation.

__pydantic_private__

Values of private attributes set on the model instance.

name: str
table_template: TableObject
version: str | None
compatibility: str | None
created_at: datetime.datetime | None
class thanosql.resources._table.TableTemplateService(client: thanosql._client.ThanoSQL)[source]

Bases: thanosql._service.ThanoSQLService

Service layer for table template methods.

client

The ThanoSQL client used to make requests to the engine.

Type:

ThanoSQL

list(search: str | None = None, order_by: str | None = None, latest: bool | None = None) List[TableTemplate][source]

Lists table templates in the workspace.

Parameters:
  • search (str, optional) – Search keywords that the table template names in the results must contain. If not set, all table templates are returned by default.

  • order_by (str, optional) –

    How to order the results. There are only three possible values:

    • recent: based on the date of creation, from most recent to oldest

    • name_asc: based on the name of the template, from A to Z

    • name_desc: based on the name of the template, from Z to A

  • latest (bool, optional) – Whether to return only the latest version of each table template. By default, or if set to False, all versions of table templates are included in the results.

Returns:

A list of TableTemplate objects.

Return type:

List[TableTemplate]

Raises:

ThanoSQLValueError – If order_by is not one of “recent”, “name_asc”, or “name_desc”.

get(name: str, version: str | None = None) dict[source]

Shows the details of the specified table template.

Parameters:
  • name (str) – The name of the table template to be retrieved.

  • version (str, optional) – The version of the table template to be retrieved. The value can either be a specific version such as “1.0”, or “latest”. If “latest” is specified, only the latest version of the table template will be shown. If version is not set, all versions will be shown.

Returns:

A dictionary of matching table template(s) in the format of:

{
    "table_templates": ["TableTemplate"],
    "versions": ["string"]
}

Return type:

dict

create(name: str, table_template: TableObject, version: str | None = None, compatibility: str | None = None) TableTemplate[source]

Creates a new table template.

Parameters:
  • name (str) – The name of the table template to be created.

  • table_template (TableObject) – TableObject containing the columns and constraints of the table template to be created. In order to create an empty table template, pass in an empty object (TableObject()).

  • version (str, optional) – The version of the table template to be created. It must be in the format of “[1-9].[0-9]”. If not set, it will default to “1.0”.

  • compatibility (str, optional) – The compatibility setting of the table template to be created. If not set, it will default to “ignore” (no compatibility checks).

Returns:

TableTemplate object of the created table template.

Return type:

TableTemplate

Raises:

ThanoSQLValueError

  • If the template name contains invalid characters or is too long.

  • If version is specified but is not in the right format.

  • If the table template contains formatting errors.

delete(name: str, version: str | None = None) dict[source]

Deletes the specified table template.

Parameters:
  • name (str) – The name of the table template to be removed.

  • version (str, optional) – The version of the table template to be removed. If not specified, all versions of the table template will be removed.

Returns:

A dictionary containing a success message and the name of the table template in the format of:

{
    "message": "string",
    "table_template_name": "string"
}

Return type:

dict