
Juacy
16.04.2017
12:59:30
sorry for my english

Alexey
16.04.2017
13:01:56

Luckydonald
16.04.2017
13:49:32

stsouko
16.04.2017
13:58:31
Passwords not unique

Google

Juacy
16.04.2017
14:00:01
I was able to store the hash with sha512, bcrypt was giving me a lot of trouble ...

Richie
16.04.2017
14:01:09
There is no other offline tool for pony, I feel so sad, cause I live in a place which is internet being scarce
right now I try to write by hand...

Luckydonald
16.04.2017
14:36:04

Richie
16.04.2017
14:36:21
agree
there would be a market for that area , I believe so

Alexey
16.04.2017
14:39:10
Currently we are not working on an offline editor
But the new version of the online tool is 99% ready
@luckydonald, we count on you as a beta tester ;)

Luckydonald
16.04.2017
14:39:30

Alexey
16.04.2017
14:40:10

Richie
16.04.2017
14:40:23
I know.. I just hope maybe some dev want to make it offline..

Janis
16.04.2017
15:19:32
I don't get the relationship running, can someone please take a look into: https://pastebin.com/raw/kTEEX4SG

Rozen
17.04.2017
12:16:45
Hi, i have a question :D
i would make any sense if i sort of edit dynamically the database structure

Google

Rozen
17.04.2017
12:17:10
to call db.generate_mapping twice?

Richie
17.04.2017
12:18:35

Rozen
17.04.2017
12:20:23
mmmm let's say that i'm creating a module that want to expand the current database that pony is using and i want that module to be used in more than one project that uses pony ?
without having to edit those projects

Richie
17.04.2017
12:23:35
I think you can

Alexander
17.04.2017
13:05:16
> i would make any sense if i sort of edit dynamically the database structure
> to call db.generate_mapping twice?
It is not possible (at least for now) to call generate_mapping twice, but you can generate entities inside a function and call that function several times with a different db objects
def define_entities(db):
class Person(db.Entity):
name = Required(str)
db1 = Database()
define_entities(db1)
db2 = Database()
define_entities(db2)

Rozen
17.04.2017
13:55:18
Thanks :D

Henry
17.04.2017
21:05:04
hey all
quick question here: if I change the entity structure in my app and restart it, can I get Pony to update the current tables, or do I have to drop the tables and start over?

Alexey
17.04.2017
21:06:43

Henry
17.04.2017
21:06:49
alright no prob
I'm still in dev phase so it's not too much of an issue

Alexey
17.04.2017
21:07:08
ok

Luckydonald
17.04.2017
21:08:07

Henry
17.04.2017
21:08:30
it'sfine.jpg

Luckydonald
17.04.2017
21:10:53
What is the best way to change out the primary key of a database?
Probably making another database and export/import?
I don't wanna do it manually, would it work to specify two different versions of the database and copy the data in python?

Alexey
17.04.2017
21:11:32
primary key of a table?

Luckydonald
17.04.2017
21:11:45

Google

Henry
17.04.2017
21:14:59
what's the pony syntax for counting the number of rows in a table?

Luckydonald
17.04.2017
21:16:28
primary key of a table?
https://editor.ponyorm.com/user/luckydonald/Tags
The `Sticker` table has a `file_id` column, which is PK.
Problem is, Telegram recent changed the way the file IDs are calculated.
So I am required to change 'em all.
Problem is many tables are referring it.
I think the best would to replace it with a Auto increment PK, in case there are future changes.

Henry
17.04.2017
21:18:25
looks like len(Entity.select()) works, is this a fine way of doing it?

Luckydonald
17.04.2017
21:19:28

Henry
17.04.2017
21:19:42
I don't know SQL well enough lol

Alexander
17.04.2017
21:20:08
any of this:
select(count() for x in MyObject).get()
get(count() for x in MyObject)
MyObject.select().count()
also possible:
select(count(x) for x in MyObject).get()
get(count(x) for x in MyObject)

Luckydonald
17.04.2017
21:21:41

Alexander
17.04.2017
21:21:46
yes

Luckydonald
17.04.2017
21:22:49

Alexander
17.04.2017
21:24:20
I think this case is too hard for migrations, because change of primary key is a very seldom operation and requires complex cascade actions. I suggest you to have two different files with definition of models, connect to both databases and copy objects from one database to another

Luckydonald
17.04.2017
21:25:21
Yeah, that was what I was thinking, too.


Alexander
17.04.2017
21:51:50
yes, but probably you need to copy some dependent objects of other types as well
If you want, you can access entity classes as db attributes, sometimes it may be more convenient
from models1 import db as db1
from models2 import db as db2
select(x for x in db1.Object)
Regarding counting the number of objects, actually the shortest form is:
orm.count(x for x in MyObject)

Luckydonald
17.04.2017
21:55:11

Alexander
17.04.2017
21:57:12
len(Entity.select()) form creates all objects in Python, it may be slow and consumes much memory. Other forms just counting the number of rows directly inside the database

Luckydonald
17.04.2017
21:58:22

Alexander
17.04.2017
21:58:43
select count(*) from table1

Luckydonald
17.04.2017
21:59:54
Oh right, forgot the count.

Google

Luckydonald
17.04.2017
22:00:14
Because it doesn't need to look at the rows content, but can just count a simple object, here a simple 1?

Alexander
17.04.2017
22:02:58
No, it compiles to the same query plan
https://asktom.oracle.com/pls/apex/f?p=100:11:0::NO::P11_QUESTION_ID:1156159920245
In all databases
http://it.blog.adclick.pt/mysql-2/mysql-count1-count-myth/

Luckydonald
17.04.2017
22:08:29

Alexander
17.04.2017
22:09:22
https://www.postgresql.org/message-id/11471.1027875769%40sss.pgh.pa.us

Luckydonald
17.04.2017
22:10:19
Huh.
The more you know!
Thanks!

Alexander
17.04.2017
22:10:35
Sure

Luckydonald
21.04.2017
18:43:51
What is the best way to apply triggers automatically in a webserver environment with pony?
http://www.revsys.com/blog/2006/aug/04/automatically-updating-a-timestamp-column-in-postgresql/

Alexander
21.04.2017
18:46:18
What do you mean 'automatically'?

Luckydonald
21.04.2017
18:58:41
I don't wanna do it manually (ssh'ing into the server etc.)
Also, is there already a Pony abstraction for triggers?

Alexander
21.04.2017
19:03:29
No, triggers are typically very database-specific. Right now we are creating them manually.
Maybe you can write a script which creates a trigger using db.execute(...)

Luckydonald
21.04.2017
19:06:24
Best would be to have a version table, and with that I can store what migrations already were processed?

Alexander
21.04.2017
19:12:39
We have such table in our migration tool. I want to finish it, but have no enough time for it, because I'm involved in other projects and they cosume all the time. I really hope that the next week I can concentrate on finishing migration tool

Luckydonald
21.04.2017
19:14:53
Yeah, I know that feeling :/
Is it possible to disable $foo automatic resolving, and force it to be needed to manually provide them, like:
db.execute("SELECT * FROM Table1 WHERE column1 = $x and column2 = $(a + b)", x="foo", a="some", b="string")
?

Alexander
21.04.2017
19:20:30
sql = "SELECT * FROM Table1 WHERE column1 = $x and column2 = $(a + b)"
var_dict = {"x": "foo", "a": "some", b: "string"}
db.execute(sql, var_dict)

Google


Luckydonald
21.04.2017
19:22:18
Oh great. This also solves the issue with my IDE complaining about unused variables.
Something different.
I am trying to use obj.to_dict(), but get
File "/Users/luckydonald/Documents/Programmieren/Python/DockerTgBot/sticker_tag_bot/code/elastic_pony/data.py", line 8, in default__to_dict
return obj.to_dict(obj)
File "<string>", line 2, in to_dict
File "/Users/luckydonald/Documents/Programmieren/Python/DockerTgBot/virtualenv3.5.1.venv/lib/python3.4/site-packages/pony/utils/utils.py", line 58, in cut_traceback
return func(*args, **kwargs)
File "/Users/luckydonald/Documents/Programmieren/Python/DockerTgBot/virtualenv3.5.1.venv/lib/python3.4/site-packages/pony/orm/core.py", line 4842, in to_dict
attrs = obj.__class__._get_attrs_(only, exclude, with_collections, with_lazy)
File "/Users/luckydonald/Documents/Programmieren/Python/DockerTgBot/virtualenv3.5.1.venv/lib/python3.4/site-packages/pony/orm/core.py", line 4073, in _get_attrs_
if only and not isinstance(only, basestring): only = tuple(only)
TypeError: 'Testclass' object is not iterable


Alexander
21.04.2017
19:38:33
only should be an attribute name or list of atribute names

Luckydonald
21.04.2017
19:40:09
Yeah, it is something deep inside pony.orm.core

Alexander
21.04.2017
19:41:21
Instead of obj.to_dict(obj) you need to write just obj.to_dict()

Luckydonald
21.04.2017
19:41:53
Yes. You are right
How does Pony handle float/double?
cc @mshekhter
https://github.com/luckydonald/elastic_pony
Permanent link to the luckydonald/elastic_pony project you mentioned. (?)

Alexander
21.04.2017
20:57:35
How does Pony handle float/double?
Pony represents float/double database type as float type in Python (which actually has double precision). The type of a database column which Pony creates is DOUBLE PRECISION. You can specify sql_type='real' if you want to create a column with a single precision


Luckydonald
21.04.2017
20:59:27
Well... you asked about get, and select is entirely different story. Pony should translate select generator code to SQL, and cannot translate your function, because it doesn't know what equivalent SQL should be. I don't know it too :)
Also, the function that you wrote expects keyword arguments, not positional ones as you use inside the query.
1) I suggest you to write selects explicitly:
games = select(g for g in Game if (g.name == name or name is None) and (g.version == version or version is None))
2) You can also build query incrementally:
query = select(g for g in Game)
if name is not None:
query = query.filter(lambda g: g.name == name)
if version is not None:
query = query.filter(lambda g: g.version == version)
3) Probably even something like that should work:
def ignore_none(query, **kwargs):
for key, value in kwargs.items():
if value is not None:
query = query.filter(lambda x: getattr(x, key) == value)
return query
query = select(g for g in Game)
query = ignore_none(query, name='X', version='Y')
I didn't test it. Theoretically it should work, but there is an open issue 223, which describes a bug with getattr which is not fixed yet. You may follow approach (2) for safety
This thing always is helpful :D
Now with correct code
(order_by(table_clazz._pk_) outside, too)