Ben
I still think there is an issue in the behaviour, as I would expect the in to not need an exact match
Alexander
You also can do something like if raw_sql(""" EXISTS ( SELECT * FROM json_object_keys(my_json_column) AS t(my_json_key) WHERE my_json_key LIKE 'Jo%' ) """)
Ben
Ohhh I didn't realise I could mix raw SQL in my queries, that is very nice. Thanks!
devSirNaelC7
Hello guys, can you help me with references to run this query with pony orm? SELECT * FROM table_secondary WHERE quantity=0 AND SYSDATE BETWEEN date_initial AND date_final I am facing problems with the documentation
Alexander
Hello guys, can you help me with references to run this query with pony orm? SELECT * FROM table_secondary WHERE quantity=0 AND SYSDATE BETWEEN date_initial AND date_final I am facing problems with the documentation
You can write it as now = datetime.datetime.utcnow() query = select( obj for obj in Secondary if obj.quantity == 0 and between(now, obj.date_initial, obj.date_final) ) In this query, I calculate the current time in Python and pass it as a parameter to a query. If you really need to use SYSDATE inside the query, you can calculate it inside a raw SQL fragment: raw_sql("SYSDATE", result_type=datetime.datetime)
М
Hello. Can I somehow set a max number of connections for pool?
Alexander
Pony pool has one connection per thread. If your application creates a big number of threads, you need to perform db.disconnect() at the end of the function (after the db_session) to close connection
devSirNaelC7
Works well, thanks
devSirNaelC7
hey guys Is it not possible to order a query that was assigned to a variable?
devSirNaelC7
q = select( (equipment.id, equipment.name, count()) for equipment in EquipmentsTypeEntity )
devSirNaelC7
if sortby: if sortby.value == 'name_asc': q = q.order_by(lambda equipmentType, name: equipmentType)
devSirNaelC7
It worked, but as development progressed, it stopped working.
devSirNaelC7
any suggestion?
Alexander
Try this form: q.order_by(lambda: equipment.name)
devSirNaelC7
A few seconds after sending the message it worked
devSirNaelC7
Thanks
Alexander
Is chat empty?
Alexander
For me it works, I see all previous messages
devSirNaelC7
Hello everyone, is there any way to get around using this column in the camera field in PoiEntity? I use the PoiEntity id to filter the POIs And if the POI type corresponds to a camera, return the POI with the camera entity data class CameraEntity(db.Entity): _table_ = "V_EM_CAMERAS" id = PrimaryKey(str, column="DWCDCLIE") name = Optional(str, column="DWNOME") information = Optional(str, column="DWDSINFO") description = Optional(str, column="DWDSECOD") link = Optional(str, column="DWCXURL") manufacturer = Optional(str, column="DWDSFABR") model = Optional(str, column="DWDSMODL") pois = Set("PoiEntity") class PoiEntity(db.Entity): _table_ = "V_EM_POIS" id = PrimaryKey(str, column="DWCDCLIE") name = Optional(str, column="NOME") code_category = Optional(str, column="CATEGORIA") category = Optional(str, column="DSC_CATEGORIA") code = Optional(str, column="PONTO") federativeUnit = Optional(str, column="ESTADO") city = Optional(str, column="CIDADE") district = Optional(str, column="BAIRRO") address = Optional(str, column="ENDERECO") postalCode = Optional(str, column="CEP") email = Optional(str, column="EMAIL") telephone = Optional(str, column="TEL") lat = Optional(float, column="DWCDCOGY") lng = Optional(float, column="DWCDCOGX") camera = Optional(CameraEntity, column="DWCDCLIE")
devSirNaelC7
I end up getting this error pony.orm.core.DBSchemaError: Column 'DWCDCLIE' already exists in table 'V_EM_POIS' and I don't know how to proceed
devSirNaelC7
Yes, I noticed, but it is necessary, I made a query to search for cameras by id separately, but I need to return this way to be efficient, if the POI type is camera, I would like some recommendations
Jayr
nice to see other PonyORM enthusiasts. I was afraid to commit to Ponyorm and the project go belly up 😄.
Christian
devSirNaelC7
I solved it guys
devSirNaelC7
😁
Radim
hello, is py3.12 supported as well?
Lucky
@metaprogrammer spam
Lucky
huh, now my telegram is displaying the group as empty.
Alexander
It is a temporary telegram glitch
Lucky
oh well, carry on :D
aldo
good morning, how may modify entity definition, like adding a column or relationship? the db already has data
Radim
you have to alter your tables manually
Radim
and then update entity definition accordingly
aldo
i see
Permalink Bot
I'm made https://github.com/luckydonald/pony_up for that.
Permanent link to the luckydonald/pony_up project you mentioned. (?)
Sergey
Hello, authors of PonyOrm. I know that it is fast. But, I'm not sure, does it support async interaction?
Alexander
Hi! Currently PonyORM does not support async natively. But you still can use it in async code. You should ensure that there is no any awaits inside db sessions: async def my_function(): ... await foo() ... with db_session: ... # no await here allowed! ... await bar()
Sergey
Thank you!
Sergey
Do you plan to add async approach?
Alexander
I'm not sure I want to add it to the current version of Pony. The way PonyORM deals with database connections and implements its in-memory cache of loaded objects is not too suitable for long-live async coroutines. But I'd like to implement a new version of PonyORM (with a slightly different API) with the following properties: 1. Full support of typing, so all Pony expressions are properly typed and recognized by IDEs like PyCharm (I've already tested that it is possible) 2. Async support 3. Migrations from the beginning 4. Dataclass-like syntax for model definitions 5. Integration with Pydantic 6. Easy conversion query results to JSON, including hierarchical data Realistically, I can't start work on it before the new year.
Alexander
Can you give an example of operations you are interested in?
Sergey
Usually I need to create or update records from pandas dataframe, f.e. 200 -1000 rows. For now I'm using for loop with PonyORM. But sometimes df.to_sql is more performant (but requires Sqlalchemy)
Alexander
Yes, I'd like to have integration with Pandas as well
Sergey
👍👍👍👍👍
Sergey
Thank you. Pony is great now, but I believe, it will be even better!
Sergey
Also Online Editor is great feature
PSoftware 👨🏻‍💻
hi
PSoftware 👨🏻‍💻
from pony.orm import Database, PrimaryKey, Required, Optional, LongStr, commit, db_session # ... (código de configuración de la base de datos y definición del modelo) # Función para insertar datos en lotes desde un archivo de texto @db_session def insertar_datos_desde_archivo(archivo): tamano_lote = 1000 lote_actual = [] with open(archivo, 'r') as f: for linea in f: campos = linea.strip().split('|') datos_registro = { 'ruc': campos[0], 'nombre_razon_social': campos[1], 'estado_contribuyente': campos[2], 'condicion_del_contribuyente': campos[3], 'ubigeo': campos[4], 'tipo_de_via': campos[5], 'nombre_de_via': campos[6], 'codigo_de_zona': campos[7], 'tipo_de_zona': campos[8], 'numero': campos[9], 'interior': campos[10], 'lote': campos[11], 'departamento': campos[12], 'manzana': campos[13], 'kilometro': campos[14] } lote_actual.append(datos_registro) if len(lote_actual) == tamano_lote: Sunat.bulk_insert(values=lote_actual) lote_actual = [] commit() # Insertar los últimos registros si no forman un lote completo if lote_actual: Sunat.bulk_insert(values=lote_actual) commit() # ... (código para definir el nombre del archivo de texto y llamar a la función)
PSoftware 👨🏻‍💻
/code
PSoftware 👨🏻‍💻
python app.py Traceback (most recent call last): File "D:\Dropbox\aplicacionesweb\bindiy\app.py", line 6, in <module> from app import app File "D:\Dropbox\aplicacionesweb\bindiy\app\__init__.py", line 3, in <module> from app.web import main File "D:\Dropbox\aplicacionesweb\bindiy\app\web\__init__.py", line 6, in <module> from app.services.department import dep File "D:\Dropbox\aplicacionesweb\bindiy\app\services\department.py", line 1, in <module> from app.modelos.basedatos import * File "D:\Dropbox\aplicacionesweb\bindiy\app\modelos\basedatos.py", line 2, in <module> from pony.orm import bulk_insert ImportError: cannot import name 'bulk_insert' from 'pony.orm' (C:\Users\calis\AppData\Roaming\Python\Python310\site-packages\pony\orm\__init__.py)
PSoftware 👨🏻‍💻
its error, please, helpme!
Alexander
its error, please, helpme!
> from pony.orm import bulk_insert There is no such method in pony.orm
PSoftware 👨🏻‍💻
what would be the solution?
Alexander
You can use Database.insert method https://docs.ponyorm.org/api_reference.html#Database.insert Or do with db_session: connection = db.get_connection() cursor = connection.cursor() # use cursor to directly bulk insert rows using SQL
Skip
I have a SQLite database. I want to both switch to a server-based db and ORM. Is there a tool which will take my SQLite schema and create the relevant Pony bits?
Mario
Any idea how to achieve this query with pony?
Santosh
select * from table where DATE(timestamp) = CURDATE();
Santosh
How do I write in Pony the date condition
Amo
Pony supports python datetime. Timestamp == datetime.now()
Radim
Hello, are you planning to work on https://github.com/ponyorm/pony/issues/694 in coming months?
Alexander
Hello, are you planning to work on https://github.com/ponyorm/pony/issues/694 in coming months?
Hi! Yes. I should have some time from January 17th to February 11th for this, so I hope to add Python 3.12 support during this period.
Radim
glad to hear that, thanks Alex!
Ben
Hello! Is it possible to determine the number of connections in the connection pool for postgres and to set a limit? I could not find anything in the doc. I would have assumed that a single process would use a single connection, but it does not seem to be the case, is there a reason why?
Alexander
Hello, this is a part of database management. ORM doesn't built to operate with those
Ben
Hmm, but it says in the doc that Pony has an inbuilt connection pool. I'm a bit confused. In general Pony opens one connection per session right?
Ben
In my case I seem to have 2 connections per Flask request (in a regular flask worker without gevent), which puzzles me
Radim
are you starting flask in debug mode?
Ben
No, it's not in debug mode. It's behind Gunicorn, I have 8 gunicorn workers handling 8 requests and somehow end up with 16 connections
Ben
My Flask request endpoint has a single db_session wrapper
Radim
alright, I am asking because I have experienced "code running twice" because of flask in debug mode
Ben
Ah it's good to know, I did not know this could happen. But it's not the case here
Ben
Ok it was my mistake, I realised that two tables I was writing to were on separate DB (even though it was the same postgres instance), it opens one connection by DB not by server.
Евгений
Можно ли использовать PonyORM без предварительного задания моделей? Типа select(o for o in Table('MyTable'))