You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
based on json.JSONEncoder from the Python Standard Library.
Because sort__keys is set to True (not the default value in the Standard Library) all dicts written to the database are sorted by key.
For [C]Python 3.7+ the order of the items when iterating over a dict is given by "Dict keeps insertion order" (GvR), which is a guaranteed language feature.
Pony should meet the language standard, so that the object retrieved from the database has the same properties as the object inserted into the database.
Program (CPython 3.11.5, Pony 0.7.17)
from pony import orm
db = orm.Database()
class JsonOnly(db.Entity):
data = orm.Required(orm.Json)
db.bind("sqlite", ":memory:", create_db=True)
db.generate_mapping(create_tables=True)
data_put = {"Z": 9, "L": [4, 5, 3], "A": 1, "D": {"DB": 2, "DA": 1}, "B": 2}
print(f"{data_put=}")
with orm.db_session:
_ = JsonOnly(data=data_put)
with orm.db_session:
data_get = JsonOnly[1].data
print(f"{data_get=}")
Python objects to be stored in a SQLite database are converted to str by (pony/orm/dbproviders/sqlite.py)
based on
json.JSONEncoder
from the Python Standard Library.Because
sort__keys
is set to True (not the default value in the Standard Library) all dicts written to the database are sorted by key.For [C]Python 3.7+ the order of the items when iterating over a dict is given by "Dict keeps insertion order" (GvR), which is a guaranteed language feature.
Pony should meet the language standard, so that the object retrieved from the database has the same properties as the object inserted into the database.
Program (CPython 3.11.5, Pony 0.7.17)
Output
The text was updated successfully, but these errors were encountered: