Alexey
Ouuu..I don't know.why you asked?
I think that having Pony work with AWS Lambda would be very convenient https://aws.amazon.com/lambda/ Serverless paradigm
Alexey
This is one of my projects https://www.korbanaqiqah.com
That's cool Let me know when you will launch that
Lucky
Huh, 99 members.
Lucky
Lemme change that :D
Lucky
@funkyKay I talked about PonyORM earlier. (The people in this chat also know SQL way better than me, lol)
Anonymous
Huh, 99 members.
the most important is the active member not the quantity😊
Anonymous
I found flask really awesome
Is it really flexible to PonyORM
Anonymous
How active is Pony development? The GitHub repo doesn't show any activity in a while
Anonymous
This is why telegram group for Pony exist.
Sorry if I wasn't clear - I wasn't referring to the community of developers who use Pony, I meant the development on Pony itself
Alexander
Recently the activity was stalled because we are working on another projects which has some deadlines. As Pony is free we cannot work on it full time. But we believe Pony has a great potential. In the near future we plan to return to more active work on Pony. We have some internal branches which needs to be merged properly before we can push them to GitHub. I hope we can do it soon.
Anonymous
Hello, Does Pony support the equivalent of an array of strings for an attribute?
Alexander
The internal brunches which need to be finish include: migrations, support of MS SQL Server, support of entity methods which can be used inside queries, better integration with JavaScript, full test suite which covers all databases and not only SQLite, refactoring of Pony code to make it more readable to external developers, etc.
Alexander
Hello, Does Pony support the equivalent of an array of strings for an attribute?
I suggest you to use JSON attributes. They can contain array of strings as well.
Anonymous
Is there a way to export the model itself to JSON?
Anonymous
Is there a way to export the model itself to JSON?
I believe there's to_dict and to_json, which might be of use.
Anonymous
Thanks. Also, can we attach validation functions to the fields?
Henri
Is it really flexible to PonyORM
Try Morepath framework. It's small but still really powerful and has now PonyORM integration through more.pony.
Anonymous
Neverheard. Is it new?
Alexander
Thanks. Also, can we attach validation functions to the fields?
You can specify py_check option to attribute: def is_email(s): return '@' in s # just an example class Person(db.Entity): email = Required(str, py_check=is_email)
Henri
Neverheard. Is it new?
Not really. It exists already for some years and the author Martijn Faassen was also the initiator of the Grok framework and many years core developer in zope. But Morepath is quite different, much cleaner and has some really powerful paradigms. http://morepath.readthedocs.io
Anonymous
ah .. I see
Anonymous
what does it specific used for?
Anonymous
I need to work now..thanks for sharing the information
Anonymous
I'm quite fond of HUG: https://github.com/timothycrosley/hug Sparse docs unfortunately.
Henri
First it was mainly intended for REST frameworks to play together with SPAs. But now it also integrates some template systems and is quite universal. It's also very extensible and modular. For a quick overview look at http://morepath.readthedocs.io/en/latest/#morepath-super-powers
Anonymous
- Does Pony have a get_or_create entity classmethod? - Also, is it possible to have an abstract class that one can inherit from, which still has methods of db.Entity but does not become a table when create_mapping is called?
Alexander
> Does Pony have a get_or_create entity classmethod? MyEntity.get(**kwargs) or MyEntity.create(**kwargs) > Also, is it possible to have an abstract class Can you explain in more details how you would use it?
Anonymous
For example I'd write a convenience get_or_create function with transaction on the abstract class Base. Then all the actual models inheriting could call this. Similarly with having a timestamp attribute which auto adds on creation.
Alexander
You can write a mixin with common methods: class MyMixin(object): def my_method(self): ... class MyEntity(MyMixin, db.Entity): ... But at this moment you need to include timestamp attribute separately to each entity: created_at = Required(datetime, default=datetime.now)
Anonymous
OK. Thank you for the prompt response. My problem with the mixin approach was that I wouldn't have access to the class in the method, so I couldn't write cls.get(**kwargs), cls.create(**kwargs) etc.
Святослав
If you want use object from get_or_create helper, whole code that use it should be wrapped by db_session. Or you should get object again by id.
Святослав
@akozlovsky right?
Alexander
If you want to write method like get_or_create it is better to define it as @classmethod so it will receive cls instead of self as first argument
Anonymous
Actually I find that I can't use inheritance at all to transfer attributes, even if the previous model inherits from db.Entity. Is this correct?
Alexander
What do you mean by "transfer attributes"?
Anonymous
class A(db.Entity): foo=Required(str) class B(A): bar=Required(str)I'd expect to have tables A and B, with B supporting foo and bar. I thought your comment about repeating the timestamp field only applied to models inheriting from a non-db.Entity class.
Alexander
There are several ways to implement inheritance in the database: 1) Each entity class & subclass maps to separate table 2) Each subclass maps to the same table as a parent class Django uses the first approach, and Pony uses the second one. Each of this approaches has benefits and drawbacks. The first way require SQL join to correctly retrieve an object from the database. The second way creates columns which contains NULL for objects which belong to other subclasses. In general, using single table for base class and subclasses is more efficient, because it does not requre SQL joins, which are slow.
Alexander
Why do you want to use separate tables for A and B classes?
Anonymous
Understood sorry I just noticed that passage in the docs.
Max
Guys, hi. Who knows how: 1) Set db_session at once for all queires (for ex. flask) 2) What is about models inheritance.. Will it work without problem with metaclasses or db connection...?
Alexander
Hi Maxim! Regarding the first question, you can do the following: @app.before_request def enter_db_session(): orm.db_session.__enter__() @app.teardown_request def exit_db_session(exc): orm.db_session.__exit__(exc and type(exc), exc) I don't fully understand the second question, I think it should work without any problems
Max
thanks, .... I also wanted to do this trick... but when i saw dbsession class i not know what method work perfectly with it...
Max
Second, is for ex .. We have some models... (db.Entity) and fields.... class A(db.Entity): class B(A): ... override somes method or fileds... It will work?
Alexander
When one entity inherits from another one, they share the same table. You cannot override fields, but you can add some methods. If yo want to have some common methods for unrelated entities, you can define them in mixin and inherit from that mixin too. If you want to override previously defined method, you need to specify mixin first. class MyMixin(object): def __str__(self): ... class MyEntity(MyMixin, db.Entity): ...
Max
I ask.. because when i used peewee .. i had problem with model inheritance... Solutions for it i did not find...It worked but with dirty code style...
Max
Hm... The table is model field? What's if i will use different table via class fields.. ? 3) SQLServer support? Is it work?
Alexander
1) In Pony, if one entity inherits from another, they share the same table, you cannot override that. For different unrelated entities you can specify _table_ explicitly for each entity 2) SQLServer support is work in progress.
Max
Hm... no? class A: _table = 'asasas' class B(A): _table = 'sdsd' print(B()._table) >sdsd
Alexander
It will not work. There are several strategies how class inheitance can be mapped to database tables. One way (used in Django) is to have separate table for each class. Another way (used in Pony) is to map all classes inherited from the same entity to a single table, and have optional columns for each inherited class. The first way is not as efficient, beause in order to retrieve an object from the database it requires join of several tables, which is slow operation. In the future we can add first type of inheritance to Pony in order to provide compatibility with Django, but right now it support single-table inheritance
Max
Alexander, Thanks a lot for all. You are the first of communicative guys in this chat ... Where are the others? 👍
Rozen
Lord of the Pony
Lucky
I am just here to watch pony.
Lucky
Using pony with postgres, setting size of an id field to 64 changes referencing values from INTEGER to BIGINT but not the fields auto increment SERIAL to BIGSERIAL. Is that intentional, an error just in the editor, or in the ORM as well?
Alexey
agreed, should be BIGSERIAL it is Pony bug too
Lucky
There's also smallserial
Lucky
https://www.postgresql.org/docs/9.6/static/datatype-numeric.html
Alexey
ok, thanks
Lucky
How do I ensure my 6+ minutes query does not time out? Has pony a limit there? db.execute('UPDATE "stickermessage" AS "sm" SET "new_sticker" = (SELECT "id" FROM "sticker" WHERE "file_id" = sm."sticker")', dict()
Alexander
Pony iself does not set any limits for query execution
Anonymous
Hi everyone!
Anonymous
Just a question regarding pony
Anonymous
Is there a way to create a pandas DataFrame by reading directly a pony select( ) object?
Anonymous
Or, alternatively, what would be a good indirect way to do so?
Alexey
hey Alberto currently the best way is to use the to_dict method of an entity https://docs.ponyorm.com/api_reference.html?highlight=to_dict#Entity.to_dict
Alexey
here you can find an example https://github.com/ponyorm/pony/issues/72
Anonymous
Thanks a lot! to_dict was what I needed
Anonymous
I created a dictionary for every object in the selection and then joined them in a DataFrame in the way explained here: https://stackoverflow.com/questions/17751626/create-a-pandas-dataframe-from-multiple-dicts
Anonymous
Hi again! I have another question. I'm trying to convert a Python project to a Windows executable file, using PyInstaller. It generates the executable, but when I try to run it, an error occurs, related to pony. The error is: " ImportError: No module named 'pony.orm.dbproviders' " Is there a way to avoid that error? Should I use another tool, like Py2exe, to create the exe file? I have the whole traceback of the error, in case it helps. Thanks in advance for any help you can provide!!
Lucky
Check if there are any files describing the dependencies to include in the Exe?