@ponyorm

Страница 72 из 75
Alexander
01.10.2018
12:04:15
?

Google
ワスドフ(Wasdf)
01.10.2018
16:38:25
sorry, it is possible to make 3 level join in a select? I want to get Diary object and name attr of Person. Diary points Contact and Contact to Person Person - Contact - Diary select((d, p.name) for d in Diary for p in c.contact.person if blabla ) But pony says NotImplementedError: for p in c.contact.person

currently im iterating to get the value

just asking if its possible

Alexander
01.10.2018
16:42:02
This is because d.contact.person is not a collection, but a single object, so you cannot iterate over it You can just write: select((d, d.contact.person.name) for d in Diary if something) Alternatively, you can write it in reverse direction: select((d, p.name) for p in Person for d in p.contacts.diary if something)

Or you can write select((d, p.name) for d in Diary for p in Person if p == d.contact.person and something)

ワスドフ(Wasdf)
01.10.2018
16:51:44
thanks again XD

Alexander
01.10.2018
16:53:05
Sure

ワスドフ(Wasdf)
01.10.2018
16:53:11
is more simple than i thought

Good morning! There is a good pattern design to apply and work with ponyorm (or an another python orm)? Im relatively new on python, im searching on internet but just in case..

Alexander
03.10.2018
08:49:24
Hi! I don't know any specific design patterns for use with orm. PonyORM itself uses multiple design patterns, such as IndentityMap https://martinfowler.com/eaaCatalog/identityMap.html UnitOfWork https://martinfowler.com/eaaCatalog/unitOfWork.html LazyLoad https://martinfowler.com/eaaCatalog/lazyLoad.html QueryObject https://martinfowler.com/eaaCatalog/queryObject.html etc

ワスドフ(Wasdf)
03.10.2018
08:51:04
Just asking to get a good logic design layers, i have a look to these links

Carel
03.10.2018
08:52:05
When using Pony, with say Tornado, i instantiate the database in one file, declare the tables in another and Do all he manipulations in my other files. This allows one to pass the database object around as necessary and lets you selectively use particular models. Also it’s as close as I could get to using pony/tornado as one might use models in Django.

Google
ワスドフ(Wasdf)
03.10.2018
08:54:14
i mean

what i understand to good design is that is necessary to make every layer do one thing and relegate to another layers other things, to work with db i thought that is a good idea have an access db layer with all methods wich access to the entities and then all the files or ocmpoents access to that access layer

im a newbie, im just asking

xD

Alexander
03.10.2018
08:59:16
I think PonyORM is *already* that separate DB layer that abstracts database usage from application code. In my practice, any separation of additional db layers leads to serious code complications, and looks like an anti-pattern

Additional separation make sense when you need to pass information to another process, for example, to JavaSctipt front-end layer. Then you need to convert retrieved entities to JSON structures

Carel
03.10.2018
09:02:46
Not sure what that is. But it, in combination with relative imports (Python > 3) allows you to pull in the models wherever it is necessary. So you can use “from . import models/database” everywhere within your package. It is a bit tricky to setup. I don’t have a public repo of this at the moment I’m afraid.

ワスドフ(Wasdf)
03.10.2018
09:05:22
thanks a lot guys

Alexander
03.10.2018
09:09:01
Carel, regarding import of db/models, it is also possible to import just db object and then access entities as an attributes of db object. Sometimes it may simplify imports from pony import orm from models import db with orm.db_session: result = orm.select(p for p in db.Person)

Alexander
03.10.2018
09:10:27
The drawback is IDEs (like PyCharm) don't understand what db.Person is and auto-complete Person attributes may not work

ワスドフ(Wasdf)
03.10.2018
09:11:59
i like the concept of static tiped in other languages, is a pain in the ass the object inspection in python imho

and, i have a last question, wich is better, pass the db object to threads class i launch or import the db on all the threads?

i see on the docs ponyorm is thread safe

Alexander
03.10.2018
09:18:59
I think there is no difference between importing and passing of db object, use what is more convenient

Also, do you write web application or desktop application?

ワスドフ(Wasdf)
03.10.2018
09:20:14
mm, service-backend application?

Google
ワスドフ(Wasdf)
03.10.2018
09:20:28
in the next weeks i will integrate with flask

but now only is a service wich read/writes the db and make thinks with the data

Carel
03.10.2018
09:21:18
@akozlovsky thanks. I’ll double check what I did in my code. I recall I needed to throw the dB instance about somewhat, hence the separate package structure.

E
04.10.2018
09:23:29
@ask does pony have a tool to generate from raw sql to pony object?

Alexander
04.10.2018
09:25:14
To generate what? Or you mean to generate raw sql?

E
04.10.2018
09:25:52
From raw sql into pony object

Alexander
04.10.2018
09:26:40
You mean generate entities from tables declaration?

E
04.10.2018
09:26:46
Yes

I do not speak english well

Alexander
04.10.2018
09:29:27
https://github.com/abetkin/pony-inspect

Permalink Bot
04.10.2018
09:29:30
https://github.com/abetkin/pony-inspect
Permanent link to the abetkin/pony-inspect project you mentioned. (?)

E
04.10.2018
09:29:30
The case if I have already make tables in sql languages and I want to try Pony and use pony query.Is there any tools to convert tables into pony class?

Alexander
04.10.2018
09:29:54
If I remeber correctly you can use this.

E
04.10.2018
09:30:10
Ah .. let me check the link

Alexander
04.10.2018
09:30:40
If you okay with redeclare entities, you can specify table name for each entity by youself

Alexander
04.10.2018
09:33:46
So take a look at pony-inspect

E
04.10.2018
09:34:30
Yes I will. Is it being tested and ready to be used ?

Alexander
04.10.2018
09:46:10
It should work for simple cases, but entity declarations sometimes may be not ideal, for example instead of many-to-many relationship you will get intermediate entity. So you may need clean up entities manually at the end

E
04.10.2018
09:47:43
Yes I had read it that python-inspect has limitations so I probably should specify tables into pony class manually

Google
E
04.10.2018
09:49:05
Is there a way to import existing pony database into pony ERD?

Alexander
04.10.2018
10:17:33
At this moment, no

E
04.10.2018
10:22:11
Okay

Grigori
04.10.2018
12:20:41
Hi guys! ` File "<auto generated wrapper of process_channel_dir_file() function>", line 2, in process_channel_dir_file File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 480, in new_func reraise(exc_type, exc, tb) File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 468, in new_func commit() File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 349, in commit transact_reraise(CommitException, exceptions) File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 319, in transact_reraise reraise(exc_class, new_exc, tb) File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 343, in commit primary_cache.commit() File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/core.py", line 1727, in commit cache.database.provider.commit(cache.connection, cache) File "/home/vader/.local/lib/python2.7/site-packages/pony/orm/dbproviders/sqlite.py", line 315, in commit provider.transaction_lock.release() CommitException: error: release unlocked lock` This error appears when I return a new ORM object creater @db_session decorated function to another @db_session decorated function. Anyone knows how to handle this?

Grigori
04.10.2018
13:00:19
no. I return object from one method to another.

Both methods a wrapped in db_session

And this happens only if I call some_binding.exists(foo=bar) before return

i.e. something inside .exists releases the lock

and it happens on .get too

but does not happen on .select

Henri
04.10.2018
13:06:30
Do you have an example?

Grigori
04.10.2018
13:08:47
it's a long one, in our codebase. I'll try to make a minimal now.

Alexander
04.10.2018
13:17:42
Hi Grigori! Do you use async libraries like Tornado in your code?

Grigori
04.10.2018
13:24:48
Twisted, that is

btw, I can't reproduce it cleanly from bottom up

but if I run any select before exists, the bug goes away

and it is 100% reproducible on our code base

nothing asyncrhonous is used in this case. It's just unit test directly calling some method.

Google
Grigori
04.10.2018
13:29:03
both the unit test and the method are wrapped in db_session

Alexander
04.10.2018
13:29:04
So, no async functions are decorated with db_session?

Grigori
04.10.2018
13:32:47
no

Alexander
04.10.2018
13:33:31
I need some time to understand what's going on

Grigori
04.10.2018
13:34:51
I kinda minimized it

the outer function: ` @db_session def test_bug(self): t = self.metadata_store.TorrentMetadata(title='test') t.delete() self.metadata_store.bug( ` Inner function: ` @db_session def bug(self): self.Metadata.exists(signature="123") return self.TorrentMetadata(title='dfdfd') `

however, I still can't reproduce it cleanly without our stack

this delete is required to trigger the bug

if I insert select(...)[:] before exists, bug goes away

yay!

I got a minimal example!

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