- All the utilities is inside the
paradedb.utilsmodule
¶
KeyField¶
KeyField is a utility class to represent a key field of a Django model or a database table, and generate SQL references. it can be used with Expressions
Parameters¶
table(Type[models.Model] | models.Model | str): The model class, model instance, or table name.-
If
str,primary_key_fieldmust also be provided. -
primary_key_field(Optional[str]): Name of the primary key field if the table is provided as a string. Optional if using a model.
Methods¶
__str__()¶
Returns the SQL representation of the key field by calling get_sql().
get_sql()¶
Generates the SQL expression for the key field:
"{table}.{key_field}"
get_lhs_sql()¶
Returns a left-hand side SQL placeholder for the key field:
"{table}.{key_field} @@@ "
get_table()¶
Returns the table name:
- If
tableis a Django model or instance, returnstable._meta.db_table. - If
tableis a string, returns the string itself.
resolve_sql_from_table_column_string(table_column_string: str) -> KeyField¶
Class method that creates a KeyField from a string in table.column format.
table_column_string(str): Expected format"table.column".
Example¶
Article.objects.filter(Match('title', 'value', key_field=KeyField(Article), match_op=True))
TableField¶
TableField represents a specific field in a table or model key field and generates SQL references.
Parameters¶
field(str): The name of the field. Required.table(typing.Optional[typing.Type[models.Model] | models.Model | str]): Name of the table. Optional ifkey_fieldis provided.key_field(typing.Optional[KeyField]): AKeyFieldinstance representing the table's key. Required iftableis not provided.
Methods¶
get_sql()¶
Generates the SQL expression for the table field:
"{table}.{field}"
tableis either provided directly or derived fromkey_field.
Example¶
Article.objects.select_related("user").filter(
Search(TableField("username", key_field=KeyField(TableUser)), "python")
)