@ponyorm

Страница 11 из 75
Serhii
10.12.2016
20:12:18
Maybe @amPerl could help with it

Romet
10.12.2016
20:14:52
i'd have to write up an example

remind me to never google "pony model" again

Luckydonald
10.12.2016
20:29:00
;:D

Google
Serge
11.12.2016
08:37:30
Funny that @akozlovsky has no admin rights in this chat:)

stsouko
11.12.2016
16:54:19
Hello! is it possible to get objects in many-to-many relations in creation order?

class Structures(db.Entity): id = PrimaryKey(int, auto=True) data = Required(LongStr) reagents = Set('Reactions', reverse='reagents') products = Set('Reactions', reverse='products') class Reactions(db.Entity): id = PrimaryKey(int, auto=True) reagents = Set(Structures, reverse='reagents') products = Set(Structures, reverse='products')

r=Reactions() r.reagents.add(s1) r.reagents.add(s2) r.reagents.add(s3) list(r.reagents)

Alexander
11.12.2016
19:40:22
Currently Set collections are unordered. You can get ordered list of items if you performs a query: r.reagents.select().order_by(lambda r: r.id)[:]

By the way it is better to name all entities in a singlular form: Structure, Reagent, etc.

Also, it looks strange that both end of relation have the same name: Structure.reagents <-> Reaction.reagents Structure.products <-> Reaction.products Typically the name is different, like: Student.courses <-> Course.students

stsouko
12.12.2016
05:59:41
Thanks. But this recipe order objects by structures. This is chemical db. Any reaction have reagents and products. And any structures may be in reagent role or product

I will rewrite many to many to combination of 2 many to one

Alexander
12.12.2016
08:33:35
Ok, now I understand. I think you should not replace many-to-many with several many-to-one, it will be not correct. I think your current scheme is good

Павел
12.12.2016
17:18:03
http://joxi.ru/KAxjMx7uMZOD0m?d=1 Thanks for magnificent ORM!

Luckydonald
12.12.2016
19:26:14
class Sticker(db.Entity): file_id = Required(str) # BQADBAAD6QIAAqQW9AX8GaFqUwWnrgI emoji = Required(unicode) # ❓ sticker_pack = Optional('StickerPack', column='sticker_pack_url') tags = Set('Tag', cascade_delete=True) sticker_messages = Set('StickerMessage') tl_id = Optional(int, size=8) # The id field of the telegram api schema the apps use. tl_access_hash = Optional(int, size=8) # The access_hash field of the telegram api schema the apps use. PrimaryKey(file_id, emoji) - class StickerPack(db.Entity): url = PrimaryKey(str) title = Required(str) owner = Required(User, column='owner_id') stickers = Set(Sticker) first_seen = Required(datetime, sql_default='NOW()')

Google
Luckydonald
12.12.2016
19:29:53
For my own reference: sticker:BQADAgADRgADyIsGAAF-kAhqVu7-1QI

Alexander
12.12.2016
19:44:08
I think this is a bug, and I'll fix it. The reason for the error is: the attribute is specified as required, but in the database its value for some object is empty string. So when Pony attempts to load that object from the database it encounters validation error. I'll change that behavior so Pony will ignore the error for empty string values loaded from the database.

Alexander
12.12.2016
20:56:32
Done: https://github.com/ponyorm/pony/commit/60ddecb060b8ea3f8637d87ec1bcbac51d8c4ddf

Have a good time of day, guys, I'm going to sleep

Luckydonald
12.12.2016
21:06:41
Thank you for the fix. Ping me when there is a new release, please

Until then pip install -e git://github.com/ponyorm/pony.git@dfedd28d02330fb351dc019f4dd03134299c23ab#egg=pony will work

---

TIL, https://telegram.me/addstickers/ is a stickerpack

https://telegram.me/StickerTagBot?start=sticker:BQADAgADRgADyIsGAAF-kAhqVu7-1QI

See the sticker pack URL

This just blow my database.

Mikki
13.12.2016
17:07:14
Welcome!

Andrew
13.12.2016
17:54:57
Thanks!

Luckydonald
13.12.2016
18:22:25
(How) can I order elements in a Set? pack = StickerPack.get(url=shortname) sticker_list = pack.stickers Now pack.stickers.order_by(Sticker.file_id)? Probably like this? stickers_list = orm.select(s for s in Sticker if s.sticker_pack and s.sticker_pack.url == shortname).order_by(Sticker.file_id)

Is that the way to do it?

Alexey
13.12.2016
18:38:36
Did it work for you?

You can have even more complex ordering condition using lambdas https://docs.ponyorm.com/api_reference.html#Set.order_by

Google
Luckydonald
13.12.2016
19:11:23
Yes, It works.

Mikki
15.12.2016
13:15:23
Welcome!

Artem
15.12.2016
13:20:10
@Mikkass Thanks.

Luckydonald
17.12.2016
15:25:45
Can I apply queries when getting elements from a Set attribute?

Summary: isinstance(pack, StickerPack) and orm.select(s for s in pack.stickers) results in TypeError: Cannot iterate over non-entity object

pack.stickers is of type orm.Set

I think I can do that on python side, with: data["stickers"] = [_sticker_to_json(s, add_pack_info=False) for s in [s_ for s_ in pack.stickers if not "nsfw" in [t.string.lower() for t in s_.tags]][:include_stickers]]

But that kinda sucks.

What is the best way to do it? Doing it in-memory on python side is not what I really want to do...

In any case, here my relevant data stucture, but it didn't change much. class Sticker(db.Entity): file_id = Required(str) # BQADBAAD6QIAAqQW9AX8GaFqUwWnrgI emoji = Required(unicode) # ❓ sticker_pack = Optional('StickerPack', column='sticker_pack_url') tags = Set('Tag', cascade_delete=True) sticker_messages = Set('StickerMessage') tl_id = Optional(int, size=8) # The id field of the telegram api schema the apps use. tl_access_hash = Optional(int, size=8) # The access_hash field of the telegram api schema the apps use. PrimaryKey(file_id, emoji) class Tag(db.Entity): id = PrimaryKey(int, auto=True) user = Required(User, column='user_id') message_id = Optional(int) # Of the message with the text, the tag. None means it got added via web gui. sticker = Required(Sticker) string = Required(unicode) use_global = Required(bool, default=False) composite_key(user, sticker, string) class StickerPack(db.Entity): url = PrimaryKey(str) title = Required(str) owner = Required(User, column='owner_id') stickers = Set(Sticker) first_seen = Required(datetime, sql_default='NOW()')

Alexander
17.12.2016
15:45:12
At this moment there is a technical limitation, that only entity class can be used as a source of generator. We can overcome it, but other tasks were more important. If you want to select from a collection you need to use lambda syntax: result = pack.stickers.select( lambda s: ...)

Luckydonald
17.12.2016
15:47:48
I'll try that, and hope this will be added eventually. But indeed this is not the most urgent feature to have :D

Not quite sure how to write that query tho

Alexander
17.12.2016
15:59:38
lambda should return true for objects you want to select. like: student1.courses.select(lambda c: c.credits > 20 and "philosophy" in c.name.lower())

Luckydonald
17.12.2016
16:00:58
Oh. I see.

I removed the if ... else ..., so It will return a boolean.

But it seems lambda s: "nsfw" not in [t.string.lower() for t in s.tags] is not possible? Still failing with TypeError: LIST_APPEND() takes 1 positional argument but 2 were given

Alexander
17.12.2016
16:10:20
Try to use generator instead of list comprehension: (...) instead of [...]

Luckydonald
17.12.2016
16:21:56
Wow, it works

This concept of using (...) instead of [...] always confuses me

Google
Alexander
17.12.2016
16:24:17
Apparently, we need to fix bytecode decompiling for [...] in last Python. They both should work. The fix should be pretty easy

Luckydonald
17.12.2016
16:24:40
I am using ... hold on

python3.5

To be exact: Docker, tiangolo/uwsgi-nginx-flask:flask-python3.5

Federico
17.12.2016
21:44:17
Hi, I'm using pony and I want to return list of results from a function with the @db_session decorator. the results are the relations from one of my classes. however when I try to access the properties of those results outside the function I get pony.orm.core.DatabaseSessionIsOver: Cannot load attribute Ramal[2].ramal: the database session is over . How can I query all properties from those objects and return them to use them later?

Alexey
17.12.2016
21:49:51
Hi Federico Why don't you process the objects inside the db_session?

Federico
17.12.2016
22:02:30
I was trying to modularize and save the results obtained in the search to be used in other functions.

Alexey
17.12.2016
22:03:42
what if you could convert the result to JSON?

Federico
17.12.2016
22:04:59
How would I do that?

Alexey
17.12.2016
22:06:58
this is something we are working on now

Federico
17.12.2016
22:10:22
glad to hear that, would it be a good idea to also add a way to copy the result to a python dictionary to be used outside the db_session?

thanks for the help, I'm really liking the orm!

Alexander
17.12.2016
22:12:14
Currently you can use to_dict method of entity instance. You can get a query result and convert it to list of dicts using a list comprehension.

Alexey
17.12.2016
22:12:26
https://docs.ponyorm.com/api_reference.html?highlight=to_dict#Entity.to_dict

Alexander
17.12.2016
22:12:53
The limitation of to_dict is may be hard to convert deep nested structures

Luckydonald
17.12.2016
22:13:13
I understiood not at all?

Alexander
17.12.2016
22:15:13
It should return attribute values as a dict values. It does not convert them to JSON-compatible values automatically. But when you call json.dumps you can pass default argument which is a function. You can pass a function which convert a timestamp to suitable representation

Google
Luckydonald
17.12.2016
22:15:46
Right. Awesome once again

BTW, how is that migration mode going on?

Federico
17.12.2016
22:16:33
awesome, thanks!

Alexander
17.12.2016
22:17:02
It is in process, we have some tests which a fail currently and want to fix them before release

Страница 11 из 75