Grigory
Its really easy to write one in Python.
Jim
But with telegram bot, you loose thr thread thing
Jim
I agree on the facr that telegram bot is very easy to work with
Adam
i looked into making a telegram bot at one point, as ive made a fully working discord bot (that has pony in it)
Jim
the function is already implemeted https://core.telegram.org/method/messages.getHistory
Adam
still would need a program to do it automaticly
Johannes
Hey,
short question into the crowd (but not very important, since it's just syntactic sugar):
Is there a way to clone an Entity-Instance (except for the id) to add a copy of it to the db?
Matthew
x = X[1]
d = x.to_dict()
del(d['id'])
X(**d)
Matthew
I think that may work, but may not handle some relationships?
Johannes
I guess this should work for my case (no child-relationships). So maybe I should just add some baseClass which adds this behaviour as a clone operator.
Jim
shorter:
```
new = X(*old.to_dict(exclude=['id']))
Jim
https://docs.ponyorm.com/api_reference.html#Entity.to_dict
Vitaliy
More universal solution:
X(**old.to_dict(exclude=[a.name for a in X._pk_attrs_])
Primary key is not necessary can be id, moreover it can be composite
Luis
Hi, how to can instance an db and tables existent whit pony, sorry for my english
Matthew
Say in your native language please
Alexander
He wants to apply pony models to existing database, I think
Jim
Looking at bufixes maybe you should remove the new releases after 7.3 and put evertyhing after 7.3 in a new 8.0 ? It could prevent auto update of dependencies since they are some backward incompatibility.
Alexander
I think it is better at this moment to specify exact version of Pony in requirements, as for projects with version < 1.0 minor version can break compatibility. Hopefully most compatibility problems should be fixed in 0.7.6 that we plan to release soon
The version 0.8-dev is used in migration branch. Because of this, it is better to release 0.8 when migrations will be ready. Hopefully it will be soon
Vitaliy
I have a question about coalese function. If I try to coalesce Json attribute pomy throws TypeError: All arguments of coalesce() function should have the same type, but in case with Json field we can not known what exactly type has an attribute. Maybe it should omit type check for Json attributes?
Vitaliy
Here is example code: select(coalesce(u.settings['remind_period'], 7) for u in User)
Luis
Como hacer uso de una base de datos existente en pony y hacer hacer actualizaciones en los registros
Alexander
Vitaliy, I think I need to fix it. Can you open an issue for this?
Vitaliy
Ok
Alexander
Luis, what database do you use? SQLite, PostgreSQL?
Alexander
You can define entities and attributes so the resulted table and columns corresponds to the original tables and columns:
class Person(db.Entity):
_table_ = 'Table1'
id = PrimaryKey(int, auto=True, coulmn='ID')
name = Required(str, column='ColumnA')
age = Required(int, column='ColumnB')
and then, when you call generate_mapping, you should not specify create_tables=True, because you want to use existing tables:
db.generate_mapping(check_tables=True)
If some tables has less number of columns than entity expects, you will get an error.
Also, you can define entities using site editor.ponyorm.com and check SQL tab corresponding to the database that you use in order to check that the existing table has the same columns.
Alexander
Also, you can try this script to automatically generate entity defnitions from existing tables:
https://github.com/abetkin/pony-inspect
Permalink Bot
Luis
Luis
Luis
I share my andvance
Luis
Luis
Thanks 👏
Alexander
So you were able to connect to existing database and select data from a table. Congrats!
Luis
Yes, its fantastic pony
Alexander
Also, keep in mind that it is not necessary to define all attributes at once in all entities. It is enough to define primary key and the most important attributes, and add the rest columns later
Alexander
You would be able to read such entities, but to create a new objects it is necessary to define all required attributes
Luis
It is much the diference😅
Alexander
Yeah, with ORM it looks a bit more concise ;)
印章
@admin could you remove those spam accounts?
Alexander
Yes, but he's offline now. They are joining like 10 per day.
Alexey
Juan Antonio
Proof
Juan Antonio
Vitaliy
Spam 2.0 :) Weird
Adam
im looking into making a bot to automatically deal with them
Grigory
Alexander , is it possible/safe to automatically generate PrimaryKey based on other attributes of the object that is being created?
For example, I have some routine that concatenates some fields of my object and then takes cryptographic hash of the result. Is it possible to use this result as a PrimaryKey without writing my own classmethods?
Say, I want to be able to write something like:
class HashedEntry(db.Entity):
propertyA = orm.Optional(buffer)
propertyB = orm.Optional(buffer)
hash = orm.PrimaryKey(buffer, default=calculateHash(str(self.propertyA)+str(self.PropertyB))
HashedEntry(propertyA="foo", propertyB="bar")
instead of having to call
HashedEntry.my_create_routine(propertyA="foo", propertyB="bar")
?
Thanks!
Alexander
you can override __init__ method:
def __init__(self, propertyA, propertyB):
hash = calculateHash(propertyA, propertyB)
super().__init__(hash=hash, propertyA=propertyA, propertyB=propertyB)
Artur Rakhmatulin
WTF
Grigory
Alexander , thanks! It's really cool that Pony does not break with this things.
印章
Vitaliy
Hi, everyone! Is there a way to track changes on Sets (M2M relationship)? I see only one way: to introduce intermediate entity and create before/after_insert callbacks, but it is not comfortable to work with (to much refactoring of existing code needed). So can I track changes of M2M Sets without intermediate entity?
Luis
Hi Alex, how to can declarate this relationship
Luis
Luis
Alexander
class Cliente(db.Entity):
_table_ = "clientes"
id = PrimaryKey(int, column="idClientes")
empresa = Optional(str, column="Empresa")
alta = Optional(str, column="Alta")
facturas = Set("Factura")
class Factura(db.Entity):
_table_ = "factura"
id = PrimaryKey(int, column="idFactura")
total = Optional(Decimal, column="Total")
...
cliente = Optional("Cliente", column="Clientes_idClientes")
Luis
Thanks, i try and and comment 👍
Luis
class Clientes(db.Entity):
_table_ = "clientes"
id = PrimaryKey(int, column = "idClientes")
Empresa = Optional(str, column = "Empresa")
Alta = Optional(str, column = "Alta")
facturas = set("Factura")
class Factura(db.Entity):
_table_ = "factura"
id = PrimaryKey(int, column = "idFactura")
Total = Optional(Decimal, column = "Total")
Fecha = Optional(datetime, column = "Fecha")
Resta = Optional(Decimal, column = "Resta")
Pagos = Optional(str, column = "Pagos")
clientes = Optional(Clientes, column = "Clientes_idClientes")
Luis
pony.orm.core.ERDiagramError: Reverse attribute for Factura.clientes not found
Alexander
facturas = set("Factura")
You need to use Set, not set
Also, it is more traditional to name all models in singular, not in plural, because an object represent a single instance of a model. It looks strange when Factura is singular, but Clientes is plural
Luis
Wow, great i am a noob 😔
Luis
Thanks Alex
Alexander
Sure
Luis
Alexander
Alexander
Cool. It is more traditional in Python to start attributes names with a lowercase letter, although it is not absolutely necessary
Luis
I need read the pep's
Yoni
Hi, does pony orm work in aws lambda ?
Alexander
As it is a pre-release, it will not be installed using an usual pip install pony command. You can install it using
pip install pony --upgrade --pre
or
pip install pony==0.7.6rc1
Tomorrow we plan to release official 0.7.6 release
Vitaliy
Cool! What is f-strings? Are there any docs?
Alexander
https://realpython.com/python-f-strings/
Artur Rakhmatulin
Vitaliy
It seems I have discovered a bug.
I have a following entity (simpified):
class IpAddress(db.Entity):
network = Required(lambda: IpNetwork)
host = Required(int, size=8, unsigned=True, min=1, index=True)
PrimaryKey(network, host)
@property
def str(self):
"""Hybrid property"""
return concat(self.network.octets, self.host)
@classmethod
def find1(cls, ipaddr):
return cls.get(lambda ip: concat(ip.network.octets, ip.host) == ipaddr)
@classmethod
def find2(cls, ipaddr):
return cls.get(lambda ip: ip.str == ipaddr)
If I call IpAddress.find1('127.0.0.1') it is OK. If I call IpAddress.find2('127.0.0.1') once it is OK, but further calls throwing exception like this:
File ".../pony/orm/core.py", line 5304, in extract_vars
try: value = extractor(globals, locals)
TypeError: 'str' object is not callable
Vitaliy
To make my app works before you'll resolve this issue I have replaced func.__globals__ to {} at line #5438 in core.py
Alexander
Thanks for reporting! I found the reson for a bug and will wix it soon
Alexander
@vitalium, I fixed the bug and pushed the fix on GitHub. Thanks again, your help with finding bugs is invaluable