Volbil
Add size=32 or size=64 to your int field
aswiro
int64
Volbil
Then you should use size=64
aswiro
Volbil
field = Required(int, size=64)
Volbil
aswiro
How get all columns value from table?
Volbil
If you need to get sum check aggregation
https://docs.ponyorm.org/aggregations.html
Yerzhan
pls help me to solve this
Volbil
pls help me to solve this
I think you should check how pony relations work
https://docs.ponyorm.org/relationships.html
Volbil
Instead of game id you should just do set of games
Alexander
Yeah and add Sales link to Games entity
Yerzhan
все равно не понятно
Aleksey
И вообще ентити лучше называть в единственном числе
Yerzhan
pony.orm.core.ERDiagramError: Reverse attribute Games.Sales not found
Aleksey
Alexander
pls help me to solve this
Entities are not tables; they are at a higher level of abstraction.
With tables, you have:
create table Games (
id primary key int,
...
)
create table Sales (
id primary key int
game_id int references Games(id)
...
)
With entities you have:
class Game(db.Entity):
...
sales = Set("Sale")
class Sale(db.Entity):
game = Required("Game")
Note that I named the attribute "game", not "game_id", because its value is an object of a Game type and not just an int id value.
This Required("Game") attribute describes a relationship between two entities, Game, and Sale. In PonyORM, each relationship is defined by two ends, so you need to have an attribute in the Game entity as well: sales = Set("Sale"). The value of this attribute is a collection of Sale objects that relate to a specific game.
Yerzhan
thanks
Yerzhan
всем спасибо
Alexander
Alexander
Thanks for reporting, should work now!
Alexander
Mario
Hey guys, can someone clarify what's the difference between OptimisticCheckError and UnrepeatableReadError? They both have a similar error message saying object X, property Y was updated outside the current transaction
Anatol
Is it possible to set default order for the Entity like in Django
class Meta:
ordering = ['created']
Anatol
Mario
Evan
hi everyone I was wondering does pony orm use encyrpted connections?
Evan
I'm trying to connect to a database I made hosted remotely so would do smth like
db.bind(provider='mysql',
host='my.host.com',
port=123456,
user='admin_user',
passwd='admin_password',
db='database_name')
Harry
Does anyone know the best way to implement tags? Is it better to use a strArray or a set to another entity called Tags?
Matt
When you say tags, what do you mean exactly? If you mean like some strings that get associated with some entity, like a tag cloud - well, depends what you're trying to achieve.
Don't think either one is "better", but the main reason you might want them in another table (entity) is if you want to query them directly, or traverse an inverse relationship, or if you plan to have a constrained set of options to choose from.
For example if you have a string array of tags on a Widget then you can simply and easily get at that when you have a Widget without another query. And you can also just add whatever string you want into that array without thinking too much about it.
But if you have a separate Tag entity then you could query for things like, find me all the tags where something, or, find me all the Widgets that have this tag attached to them.
A
Hi everyone cá I use Jupyter and with poni Orm ?
Harry
Hey all ! I just downloaded python 3.11 and it seems there's a breaking change w/ pony. Only basic .get() queries seem to work. Using "orm.select(e for e in myEntity)" will raise this error "DecompileError: Unsupported operation: RETURN_GENERATOR" I just switched back to python version 3.10.4 and the same code that raises that decompile error in 3.11 works fine
Harry
Sorry I can't be more clear w/ code examples I only have telegram on my phone at the moment
Alexander
Thank you for reporting! We need to add support of Python 3.11. Hope we can do it the next weekend
Harry
Sounds good! Thank you!!
Alexander
Since they gonna improve python bytecode in a next several years - Pony will need to be updated a lot
Muhammed
Hi everyone, I want to define a column of the table as json. But when I call this column, I want it to return as a custom class that I defined. Is this possible?
Alexander
class MyJson(...):
attr1: ...
attr2: ...
@classmethod
def from_json(cls, vals):
return cls(...**vals)
class MyEntity(db.Entity):
values = Optional(Json)
def foo(self):
return MyJson.from_json(self.values)
a = MyEntity.get(...)
obj = a.foo()
Muhammed
Thanks for your reply. This method can be used. But I will use the MyJson class for multiple columns. So I will have to write getter for each column. It would better for me if I could create an inherited class from Json instead of getter and use it as column = Optional(MyJson).
Alexander
You can use as many columns as you wish
class MyEntity(db.Entity):
values = Optional(Json)
prices = Optional(Json)
def foo(self):
return MyJson.from_json(**self.values, **self.prices)
Enoch
Hello here
Please I'm new to Pony
I get operationalerror when I run db.bind(provider='sqlite', filename ='database.sqlite', create_db = True), In accordance with the documentation
Enoch
But I get operationalerror unable to open database file
Can someone help me out please 🙏
Volbil
Enoch
It's 3.9.12
Alexander
Evan
hi i'm trying to connect to a mysql using ssl and I have a ca-certificate from the db provider
Evan
I only see an example using anythign similar here:
db.bind(provider='cockroach', user='', password='', host='', database='',
port=26257, sslmode='require', sslrootcert='certs/ca.crt',
sslkey='certs/client.maxroach.key', sslcert='certs/client.maxroach.crt')
but for mysql it seems this is not supported?
Alexander
I feel these names are incorrect.
Alexander
You can check out them here
https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html
Alexander
For example what you call sslrootcert is ssl_ca
Alexander
I guess all connectors have same naming convention. LIke here they're the same https://pymysql.readthedocs.io/en/latest/modules/connections.html
Evan
basically you're saying the **kwargs that bind takes when provider is 'mysql' should match whatever is going on in pymsql correct?
Alexander
I was saying that both mysql-connector and pymysql use exact same names for connection parameters.
And they do not match yours.
Evan
yup got it makes sense thank you
A
can you please
A
can you tell why the data cannot be seen in relational database management please?
A
A
Anyone have idea ?
Alexander
I do not really understand what are you trying to do.
Oualid
did we will see ponyorm support the coroutines
in next update !!
Volbil
Anatol
Hi,
How to avoid
pony.orm.core.ERDiagramError: Entity Service already exists during the class declaration
class Service(db.Entity):
I'm trying to use PonyORM with pytest and pdoc
Alexander
You cannot have two different entities with the same name Service for a single db:
db = Database(...)
class Service(db.Entity):
...
class Service(db.Entity): # error
...
Anatol
Yes, I've figured that. Now trying to understand how to pytest the module related to the database (reuse the model)
Anatol
And how to generate documentation with pdoc3 as during the generation it shows the same error
Alexander
Anatol
Lucky
Also resurecting an old topic:
Python Enums.
I still have ticket #502 with pull request #585 laying around.
Any chance this could get a review?
The way it works is actually quite simple:
In python, enums are a subtype of both Enum, and a base type (int, str, bool, etc.)
In other words code:
value = SomeEnum.SOME_VALUE
isinstance(value, int) == True
This means we can simply use those values which is backing the enums as database values.
All this PR does is checking the enum type for what the underlying type would be processed as (self._get_real_converter(py_type, attr)), and store that converter internally (self.converter).
Now all the fancy converter methods (py2sql, sql2py, val2dbval, …) will be forwarded to that chosen converter.
That's it.
Bonus feature: It chooses the size of the integer or string colums correctly if you don't provide those.
Matthew
Matthew
Alexander
That's amazing! There are some minor differences in column definitions, but it looks like it can "understand" the general concept :)
Alexander
Also resurecting an old topic:
Python Enums.
I still have ticket #502 with pull request #585 laying around.
Any chance this could get a review?
The way it works is actually quite simple:
In python, enums are a subtype of both Enum, and a base type (int, str, bool, etc.)
In other words code:
value = SomeEnum.SOME_VALUE
isinstance(value, int) == True
This means we can simply use those values which is backing the enums as database values.
All this PR does is checking the enum type for what the underlying type would be processed as (self._get_real_converter(py_type, attr)), and store that converter internally (self.converter).
Now all the fancy converter methods (py2sql, sql2py, val2dbval, …) will be forwarded to that chosen converter.
That's it.
Bonus feature: It chooses the size of the integer or string colums correctly if you don't provide those.
Thanks for reminding, I should be able to look at it in a few days
Karsten
Hello Alexander,
I save a data set and then want to use this data set to output attributes in the gui.
The following exception is thrown:
Cannot load attribute BlzEvent[49209].time_from
This only happens with attributes with the value None !
Can you help me ?
Many Thanks
Karsten
class BlzEvent(db.Entity):
_table_ = 'blz_events'
id = PrimaryKey(int, auto=True) # 0 - hidden
net = Required(str, index=True) # 1 - hidden
reporter = Required(str) # 2
...
distance = Optional(float) # 15
time_from = Optional(time) # 16
time_to = Optional(time) # 17
delay = Optional(int) # 18
operator = Required(str) # 19
# only for administrators
creation_time = Required(datetime) # 20 - visible for administrators
action = Optional(str) # 21 - visible for administrators
exec_operator = Optional(str) # 22 - visible for administrators
action_time = Optional(datetime) # 23 - visible for administrators
@db_session
def add_blz_event(net, reporter, reporter_func, event_time, line, train, location, code, code_description,
category, comment, from_location, to_location, dist_manually,
distance, time_from, time_to, delay, operator, creation_time):
try:
blz_event = BlzEvent(net=net,
reporter=reporter,
...
dist_manually=dist_manually,
distance=distance,
time_from=time_from, # in exsample set None
time_to=time_to, # in exsample set None
delay=delay, # in exsample set None
operator=operator,
creation_time=creation_time)
flush()
return blz_event
except Exception as ex:
return -1
result: BlzEvent = self._dal.add_blz_event(self._net, ..., comment, from_loc, to_loc, False, distance,
None, None, None, self._operator, datetime.now())
x = result.time_from (in exsample set None)
Exception = pony.orm.core.DatabaseSessionIsOver: Cannot load attribute BlzEvent[49209].time_from: the database session is over
Amo
Karsten I don't know why it works for not None values but could you try to return the object as json from add_blz_event?