Declaring a JSON attribute
For declaring a JSON attribute with Pony you should use the Json
type. This type can imported from pony.orm
package:
from pony.orm import *
db = Database()
class Product(db.Entity):
id = PrimaryKey(int, auto=True)
name = Required(str)
info = Required(Json)
tags = Optional(Json)
db.bind('sqlite', ':memory:', create_db=True)
db.generate_mapping(create_tables=True)
The info
attribute in the Product
entity is declared as Json
. This allows us to have different JSON structures for different product types, and make queries to this data.