sqlalchemy_singlestoredb.JSON¶
- class sqlalchemy_singlestoredb.JSON(*args: Any, **kwargs: Any)¶
SingleStore JSON data type for storing structured JSON data.
SingleStore’s native JSON data type supporting structured data storage and querying.
Examples
Table Usage:
from sqlalchemy import Column, Integer, MetaData, Table from sqlalchemy_singlestoredb import JSON metadata = MetaData() documents = Table( 'documents', metadata, Column('id', Integer, primary_key=True), Column('metadata', JSON), Column('tags', JSON), )
ORM Usage:
from sqlalchemy import Column, Integer, String from sqlalchemy.orm import declarative_base from sqlalchemy_singlestoredb import JSON Base = declarative_base() class Document(Base): __tablename__ = 'documents' id = Column(Integer, primary_key=True) title = Column(String(200)) metadata = Column(JSON) tags = Column(JSON)
With Multi-Value Indexes:
For efficient querying of JSON arrays, combine with MultiValueIndex:
from sqlalchemy_singlestoredb import JSON, MultiValueIndex class Article(Base): __tablename__ = 'articles' id = Column(Integer, primary_key=True) tags = Column(JSON) __table_args__ = { 'singlestoredb_multi_value_indexes': [MultiValueIndex('tags')], }
- __init__(*args: Any, **kwargs: Any) None¶
Construct a
_types.JSONtype.- Parameters:
none_as_null=False –
if True, persist the value
Noneas a SQL NULL value, not the JSON encoding ofnull. Note that when this flag is False, thenull()construct can still be used to persist a NULL value, which may be passed directly as a parameter value that is specially interpreted by the_types.JSONtype as SQL NULL:from sqlalchemy import null conn.execute(table.insert(), {"data": null()})
Note
`_types.JSON.none_as_null` does not apply to the values passed to `_schema.Column.default` and `_schema.Column.server_default`; a value of
Nonepassed for these parameters means “no default present”.Additionally, when used in SQL comparison expressions, the Python value
Nonecontinues to refer to SQL null, and not JSON NULL. The `_types.JSON.none_as_null` flag refers explicitly to the persistence of the value within an INSERT or UPDATE statement. The_types.JSON.NULLvalue should be used for SQL expressions that wish to compare to JSON null.See also
types.JSON.NULL
Methods
__init__(*args, **kwargs)Construct a
_types.JSONtype.adapt(cls, **kw)Produce an "adapted" form of this type, given an "impl" class to work with.
as_generic([allow_nulltype])Return an instance of the generic type corresponding to this type using heuristic rule.
bind_expression(bindvalue)Given a bind value (i.e. a
BindParameterinstance), return a SQL expression in its place.bind_processor(dialect)Return a conversion function for processing bind values.
coerce_compared_value(op, value)Suggest a type for a 'coerced' Python value in an expression.
column_expression(colexpr)Given a SELECT column expression, return a wrapping SQL expression.
compare_values(x, y)Compare two values for equality.
compile([dialect])Produce a string-compiled form of this
TypeEngine.copy(**kw)copy_value(value)dialect_impl(dialect)Return a dialect-specific implementation for this
TypeEngine.evaluates_none()Return a copy of this type which has the
should_evaluate_noneflag set to True.get_dbapi_type(dbapi)Return the corresponding type object from the underlying DB-API, if any.
literal_processor(dialect)Return a conversion function for processing literal values that are to be rendered directly without using binds.
result_processor(dialect, coltype)Return a conversion function for processing result row values.
with_variant(type_, *dialect_names)Produce a copy of this type object that will utilize the given type when applied to the dialect of the given name.
Attributes
NULLDescribe the json value of NULL.
hashableFlag, if False, means values from this type aren't hashable.
python_typeReturn the Python type object expected to be returned by instances of this type, if known.
render_bind_castRender bind casts for
BindTyping.RENDER_CASTSmode.render_literal_castrender casts when rendering a value as an inline literal, e.g. with
TypeEngine.literal_processor().should_evaluate_noneAlias of
_types.JSON.none_as_nullsort_key_functionA sorting function that can be passed as the key to sorted.