sqlalchemy_singlestoredb.MultiValueIndex¶
- class sqlalchemy_singlestoredb.MultiValueIndex(*columns: str, index_options: str | Dict[str, Any] | None = None)¶
SingleStore MULTI VALUE INDEX DDL element.
Represents a MULTI VALUE INDEX for indexing JSON array values, enabling efficient queries on individual array elements.
- Parameters:
*columns (str) – Variable number of column names to include in the multi-value index. Must be JSON columns.
index_options (str or Dict[str, Any], optional, keyword-only) – Index options for the multi-value index. Can be either a JSON string or a dictionary that will be automatically JSON-serialized.
Examples
Basic multi-value index:
>>> MultiValueIndex('tags')
Multiple columns multi-value index:
>>> MultiValueIndex('tags', 'categories')
Multi-value index with options:
>>> MultiValueIndex('tags', index_options={'some_option': 'value'})
Table Usage:
from sqlalchemy import Column, Integer, MetaData, Table from sqlalchemy_singlestoredb import JSON, MultiValueIndex metadata = MetaData() articles = Table( 'articles', metadata, Column('id', Integer, primary_key=True), Column('tags', JSON), singlestoredb_multi_value_indexes=[MultiValueIndex('tags')], ) # Multiple columns products = Table( 'products', metadata, Column('id', Integer, primary_key=True), Column('tags', JSON), Column('categories', JSON), singlestoredb_multi_value_indexes=[ MultiValueIndex('tags', 'categories'), ], )
ORM Usage:
from sqlalchemy import Column, Integer from sqlalchemy.orm import declarative_base from sqlalchemy_singlestoredb import JSON, MultiValueIndex Base = declarative_base() class Article(Base): __tablename__ = 'articles' id = Column(Integer, primary_key=True) tags = Column(JSON) __table_args__ = { 'singlestoredb_multi_value_indexes': [MultiValueIndex('tags')], } class Product(Base): __tablename__ = 'products' id = Column(Integer, primary_key=True) tags = Column(JSON) categories = Column(JSON) __table_args__ = { 'singlestoredb_multi_value_indexes': [ MultiValueIndex('tags', 'categories'), ], }
Notes
Multi-value indexes are used to index JSON arrays in SingleStore. They allow efficient queries on individual elements within JSON arrays. The columns must be of JSON type for multi-value indexing to work properly.
Methods
__init__(*columns[, index_options])against(target)Return a copy of this
_schema.ExecutableDDLElementwhich will include the given target.compare(other, **kw)Compare this
_expression.ClauseElementto the given_expression.ClauseElement.compile([bind, dialect])Compile this SQL expression.
execute_if([dialect, callable_, state])Return a callable that will execute this
_ddl.ExecutableDDLElementconditionally within an event handler.execution_options(**kw)Set non-SQL options for the statement which take effect during execution.
get_children(*[, omit_attrs])Return immediate child
visitors.HasTraverseInternalselements of thisvisitors.HasTraverseInternals.get_execution_options()Get the non-SQL options which will take effect during execution.
memoized_instancemethod(fn)Decorate a method memoize its return value.
options(*options)Apply options to this statement.
params([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()elements replaced.self_group([against])Apply a 'grouping' to this
_expression.ClauseElement.unique_params([_ClauseElement__optionaldict])Return a copy with
_expression.bindparam()elements replaced.Attributes
allows_lambdadescriptionentity_namespaceinherit_cacheIndicate if this
HasCacheKeyinstance should make use of the cache key generation scheme used by its immediate superclass.is_clause_elementis_deleteis_dmlis_from_statementis_insertis_selectis_selectableis_textis_updatestringify_dialectsupports_executiontargetuses_inspectioncolumnsindex_optionsnegation_clauseproxy_set