main commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-16 16:30:25 +09:00
parent 91c7e04474
commit 537e7b363f
1146 changed files with 45926 additions and 77196 deletions

View File

@@ -1,5 +1,5 @@
# ext/indexable.py
# Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
# ext/index.py
# Copyright (C) 2005-2023 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
@@ -36,19 +36,19 @@ as a dedicated attribute which behaves like a standalone column::
Base = declarative_base()
class Person(Base):
__tablename__ = "person"
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
data = Column(JSON)
name = index_property("data", "name")
name = index_property('data', 'name')
Above, the ``name`` attribute now behaves like a mapped column. We
can compose a new ``Person`` and set the value of ``name``::
>>> person = Person(name="Alchemist")
>>> person = Person(name='Alchemist')
The value is now accessible::
@@ -59,11 +59,11 @@ Behind the scenes, the JSON field was initialized to a new blank dictionary
and the field was set::
>>> person.data
{'name': 'Alchemist'}
{"name": "Alchemist'}
The field is mutable in place::
>>> person.name = "Renamed"
>>> person.name = 'Renamed'
>>> person.name
'Renamed'
>>> person.data
@@ -87,17 +87,18 @@ A missing key will produce ``AttributeError``::
>>> person = Person()
>>> person.name
...
AttributeError: 'name'
Unless you set a default value::
>>> class Person(Base):
... __tablename__ = "person"
...
... id = Column(Integer, primary_key=True)
... data = Column(JSON)
...
... name = index_property("data", "name", default=None) # See default
>>> __tablename__ = 'person'
>>>
>>> id = Column(Integer, primary_key=True)
>>> data = Column(JSON)
>>>
>>> name = index_property('data', 'name', default=None) # See default
>>> person = Person()
>>> print(person.name)
@@ -110,11 +111,11 @@ an indexed SQL criteria::
>>> from sqlalchemy.orm import Session
>>> session = Session()
>>> query = session.query(Person).filter(Person.name == "Alchemist")
>>> query = session.query(Person).filter(Person.name == 'Alchemist')
The above query is equivalent to::
>>> query = session.query(Person).filter(Person.data["name"] == "Alchemist")
>>> query = session.query(Person).filter(Person.data['name'] == 'Alchemist')
Multiple :class:`.index_property` objects can be chained to produce
multiple levels of indexing::
@@ -125,25 +126,22 @@ multiple levels of indexing::
Base = declarative_base()
class Person(Base):
__tablename__ = "person"
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
data = Column(JSON)
birthday = index_property("data", "birthday")
year = index_property("birthday", "year")
month = index_property("birthday", "month")
day = index_property("birthday", "day")
birthday = index_property('data', 'birthday')
year = index_property('birthday', 'year')
month = index_property('birthday', 'month')
day = index_property('birthday', 'day')
Above, a query such as::
q = session.query(Person).filter(Person.year == "1980")
q = session.query(Person).filter(Person.year == '1980')
On a PostgreSQL backend, the above query will render as:
.. sourcecode:: sql
On a PostgreSQL backend, the above query will render as::
SELECT person.id, person.data
FROM person
@@ -200,14 +198,13 @@ version of :class:`_postgresql.JSON`::
Base = declarative_base()
class Person(Base):
__tablename__ = "person"
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
data = Column(JSON)
age = pg_json_property("data", "age", Integer)
age = pg_json_property('data', 'age', Integer)
The ``age`` attribute at the instance level works as before; however
when rendering SQL, PostgreSQL's ``->>`` operator will be used
@@ -215,9 +212,7 @@ for indexed access, instead of the usual index operator of ``->``::
>>> query = session.query(Person).filter(Person.age < 20)
The above query will render:
.. sourcecode:: sql
The above query will render::
SELECT person.id, person.data
FROM person