@ponyorm

Страница 2 из 75
Rozen
24.09.2016
00:16:42
but that's exactly what i have and the query i'm trying to do

and that's what i get u.u

(the error)

Alexander
24.09.2016
00:19:52
Can you provide full exception traceback? It may contain some hints

Google
Rozen
24.09.2016
00:22:48
Dont know how xD

Alexander
24.09.2016
00:23:37
The error `<class 'pony.orm.sqltranslation.IncomparableTypesError'> ("Incomparable types 'Animal' and 'Set of Dog' in expression: h.pet == dog",)` came with some traceback

Rozen
24.09.2016
21:05:41
well, i don't know what maybe i've done wrong before

but now that works

sorry for the trouble

noow i have another question

if i have a function that returns an User object, and User inheritates from db.Entity

if the .. scope that called the function that returned that User object it's wrapped in db_entity it will get that is the same user as in the table?

or i should "load" it again?

Alexander
24.09.2016
22:55:30
Yes, within the same db_session it will be the same object if primary key value is the same

Rozen
25.09.2016
15:43:03
thanks :D

Annnnnnnnnother silly question(sorry, i guess i don't have too much experience u.u)

Hmm well basically i would ask "what could i do if the database is locked"

Google
Rozen
25.09.2016
15:46:46
i was thinking of just using @retry at best

or try to make a buffer

but to me that seems a little odd while using pony ?

Alexey
25.09.2016
16:45:03
Can you describe the scenario when you get the database locked?

Rozen
25.09.2016
16:45:19
having 3 processes that access the same database at the same time

Alexander
25.09.2016
16:57:51
In SQLite only one process can modify database at a time. After the process issues an INSERT, UPDATE or DELETE command, the database is in locked state. If another process tries to work with the database at this moment, it will be suspended until the first process finishes its transaction. SQLite has timeout (which defaults to 5 seconds), after which the suspended process got exception "The database is locked". In order to avoid that exception, you need to complete transaction in the first process before the timeout. In Pony a transaction can be finished in following ways: - implicitly, upon exit from db_session scope - explicitly, using commit() or rollback() Your process that saved changes to database should perform commit() or rollback() after some portion of data was saved, or exit from db_session in order to have implicit commit. It should not stay within db_session indefinitely without performin commit or rollback

Rozen
29.09.2016
15:53:27
mm

to use the retry option

only can used on @db_session?

like..

i cant do with db_session(retry=3): #code

?

Alexander
29.09.2016
15:54:58
Yes, this is Python restriction for context managers, their code cannot be automatically executed several times

Rozen
29.09.2016
15:55:12
wokey ty ?

Vitalii
03.10.2016
10:26:10
while db_session.error(retry=3): # codeeverything is possible in python ;)

No, here is it with db_session.retry(3) as retry: while retry: # code

Alexander
03.10.2016
10:38:59
So you mean that we can add such extension to API

Vitalii
03.10.2016
10:39:13
NO! :)

Rozen
06.10.2016
16:19:48
another round of "Rozen's stupid questions!" yey!

if i have db1 and db1 class hello(db1.Entity): blablablal

Google
Rozen
06.10.2016
16:20:45
can i have like... class wololo(db2.Entity): helloes = Set("Hello") ?

Alexey
06.10.2016
16:21:22
hey nope, all related entities should belong to the same database

Vitalii
06.10.2016
16:21:24
yes you can afaik

Alexey
06.10.2016
16:21:56
but if they are not related, then you can

Vitalii
06.10.2016
16:22:21
right, i didn't notice they were related

Rozen
06.10.2016
16:22:47
hmm wokey

and if i have... a relational table in one of the databases?

well, actually i have no idea what i'm talking about ?

Alexey
06.10.2016
16:24:00
haha)

Alexander
06.10.2016
17:20:44
Why do you want to split tables between several databases? It is better to keep related tables together, because then the database can enforce foreign key constraints in order to be sure that all used ids have corresponding rows. It is possible to keep tables in different databases, but then you are vulnerable to data consistency issues and need to process joins manually.

Rozen
06.10.2016
17:21:30
it was just an idea ?

Alexander
06.10.2016
17:22:14
By default try to store everything in a single database, it will be simpler

Rozen
06.10.2016
17:23:46
yes yes ? i was and idea beause i wanted to avoid to have lots of database locking ?

i'm having tons of database writing at the same time ?

i have retry=30 and everything but it crashes anyway ?

Alexander
06.10.2016
17:29:01
That means that db_session from which you perform an update stays open for too long. Ideally, all transactions which perform writing to the database should be very short. Maybe you start db_session, perform an update and then start some unrelated actions, like, sending e-mail via SMTP. In that case the database remains locked until the email is sent, and it may take a long time. It is better to perform such long unrelated operations outside of db_session

Rozen
06.10.2016
17:30:05
mmmmmmmmm

i'll see

Mikki
07.10.2016
08:54:16
Smaller transactions is always better. If you have to retry 30 times, think about why you wanted to use a db again :p

Rozen
07.10.2016
13:39:54
ajamm

Google
Rozen
07.10.2016
13:40:55
This works? with db_session: hoomans = select(h for h in Human) for h in hoomans: print(h.name)

(or it's even necesary to use de db_session for just a select?)

Alexander
07.10.2016
13:44:21
You should wrap all interactions with objects in a single db_session: with db_session: hoomans = select(...) for h in hoomans: print(h.name) An attribute access like h.name potentially can lead to SQL query, and SQL queries are possible inside db_session only.

Rozen
07.10.2016
13:44:53
ok ok, got it ?

Admin


Rozen
07.10.2016
13:45:14
i'm not quite sure how generators work so maaaybeee it worked (?)

mm

but if i do hoomans = (h.name for h in Human) ?

Alexander
07.10.2016
13:48:05
generators are lazy, the real operation will be performed later. You need to use list comprehension to eval result inside db_session: with db_session: hoomans = select(...) names = [h.name for h in hooman] Then you can use names outside of db_session

Rozen
07.10.2016
13:49:13
right

thanks :D

Mikki
12.10.2016
07:50:18
Helleau!

pandaconqueso?
12.10.2016
07:54:05
hello :D

Mikki
12.10.2016
19:38:53
And hello to you two too!

Null
12.10.2016
20:08:36
Ahoj

Mikki
17.10.2016
12:01:03
Welcome!

Alex
17.10.2016
12:08:49
Hello, thank you!

Rozen
17.10.2016
12:14:13
mm i don't get it very well, what's the point of getattr for databases?

Alexey
17.10.2016
12:15:46
you are talking about this feature https://docs.ponyorm.com/api_reference.html#getattr, right?

Rozen
17.10.2016
12:15:54
yep ?

Google
Alexey
17.10.2016
12:17:51
it gives you more flexibility in writing queries

you don't need to hardcode which attribute you extract or compare, but can pass the name of these attributes as a parameter

Alexander
17.10.2016
12:21:19
This may be useful when somebody write some generic code for filtering. For example, when the name of the attribute may be received from the frontend as a GET parameter

Mikki
18.10.2016
16:57:28
Welcome!

Rit
18.10.2016
17:01:24
Thank you. The switch to Apache License showed up on my twitter feed. I'm going forward to try it.

looking*

Rozen
18.10.2016
17:02:47
(sorry sorry, i got tempted)

Mikki
18.10.2016
20:59:19
Welcome!

Welcome! :)

Manuel
19.10.2016
12:45:37
Thanks! Never used pony before 'cause of the license, somehow I had the wrong idea it was too restrictive

it really is a beautiful ORM, kudos!

Mikki
19.10.2016
12:46:41
Glad to hear that you're liking it! ^.^

(note, Im not a dev but just an enthousiastic user :p )

Mikhail
19.10.2016
13:27:25
Same, usually used peewee for small projects, but now license allows to use pony; watching videos on youtube so far, testing, interesting.

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