Ben
Hey! Is there a reason Pony does not use LOWER() when using .lower() in the query in Python and instead uses replace? Is there a way to force it? It would make searches faster
SlavaMGTU
Hey! I am trying to work in PonyORM . Please tell me, there is some method that allows you to determine the maximum value ID in the table. Now I use for this loops
Alexander
select(max(obj.id) for obj in MyEntity) or from pony.orm import max ... max(obj.id for obj in MyEntity) or select(obj.id for obj in MyEntity).max()
SlavaMGTU
Thank you
SlavaMGTU
I have MyEntitys: Product and Tag and relationship. I have line Product1 in Product and tags_set {'tag1', 'tag3'} this Product1. I have lines 'tag1', 'tag2', 'tag3' in Entity “Tag”. When I used code: query_tag = select(t for t in Tag if t.tag_name == tag_name) I can’t connect lines 'tag1', 'tag3' with line Product1. Only using cycles. Please tell me, Can I use pony methods to determine this “id” lines Entity “Tag”.?
SlavaMGTU
Alexander
# retrieving tags for specific product id product = Product[specific_product_id] for tag in product.tag_set: print(tag.name) # retrieving a product for specific tag name tag = Tag.get(name=specific_tag_name) for product in tag.product_set: print(product.name)
SlavaMGTU
I have line Product1 in Entity “Product”, lines 't1', 't2', 'q1' in Entity “Tag” They have relationships. and String 't2, t1, q1, tag1, tag10' Please let me know, how do I detect which tags have relationships with an entity Product1 ?
Vitaliy
The same as Alexander replied above. product1 = Product.get(Name='product 1') tags = select(t for t in product1.tags) or tag_names = select(t.tag_name for t in product1.tags)[:]
Peter
Can someone recommend a video on how yo use pony ORM
Peter
🙏?
SlavaMGTU
The same as Alexander replied above. product1 = Product.get(Name='product 1') tags = select(t for t in product1.tags) or tag_names = select(t.tag_name for t in product1.tags)[:]
Thank you very much !!! it works. Please, tell me, where can I find out about these square quotes at the end of a string code?
Christian
Can someone recommend a video on how yo use pony ORM
Hi Peter. There is this series of videos of youtube, which you probably found as well: https://www.youtube.com/watch?v=YyTGYk1j9N0&list=PLM0LBHjz37LXPeEjSuumB4g4JFCsTwNgn
Christian
Personally, I'd recommed just going through the first steps on the docs page: https://docs.ponyorm.org/firststeps.html
Peter
Thank you @christiandoes , I appreciate 🙏
Tenny G
Good day everyone please, how can I read and parse four files in these format .CSV,.JSON, .XML and .txt into a single database table using ponyORM Thank you very much in anticipation
Christian
Good day everyone please, how can I read and parse four files in these format .CSV,.JSON, .XML and .txt into a single database table using ponyORM Thank you very much in anticipation
You create the database with PonyORM and use python's standard library tools to parse each file and put the contents into your db table. Here are some examples that will help you: https://docs.python.org/3/library/csv.html#examples https://docs.python.org/3/library/json.html https://docs.python.org/3/library/xml.etree.elementtree.html#parsing-xml
Christian
Thank you for the above but I am stocked in joining related column in CSV and JSON and parse it as a single file using ponyORM. Still need further assistance
Sorry, I don't understand. If you have four different filetypes, why would you parse it as a single file?
Christian
Do you have some code that shows what you're trying to do?
Evan
do you know if i can use the pony with pandas.to_sql this typically needs a sqlalchemy connection / engine instance https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html
Henri
Are there any problems with PR #671? Would be nice to have Python 3.11 compatibility, https://github.com/ponyorm/pony/pull/671
A
Thank you very much !!! it works. Please, tell me, where can I find out about these square quotes at the end of a string code?
Off-topic, but... if you didn't work it out yet, the [:] syntax is how Python slices (i.e. selects parts from) arrays and other iterables (including strings). See https://stackoverflow.com/questions/509211/understanding-slicing
A
do you know if i can use the pony with pandas.to_sql this typically needs a sqlalchemy connection / engine instance https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html
Personally, i don't know but i doubt it. Pandas.DataFrame.to_sql only supports SQL Alchemy, or SQLite3 as a "legacy" option according to those docs. Perhaps you could dump the DataFrame to a SQLite database, then connect to that with Pony? I have no idea if that is a Good Plan, though :)
Evan
how do i declare a text column - I'm running into issues with long strings when I use the orm.Required(str) syntax
Evan
thank you
PirraToZ
Здравствуйте, можете подсказать как мне писать тесты с ponyorm, использую pytest? Буду рад примерам,в интернете не нашёл.
PirraToZ
how to properly initialize the database for tests? This is my initialization, but it doesn't separate the tests from each other.
Alexander
Are you familiar with pytest.fixture?
Alexander
There a lot of ways you can achieve this, but the easiest one would be def initialize_db_here(): ... @pytest.fixture() def db(): _db = initialize_db_here() yield _db destruct_db() def test(db): ... # work with your db Probably smth like this could work
PirraToZ
I saw this method on the Internet, but it seems incorrect to me, but thanks anyway)
Henri
I saw this method on the Internet, but it seems incorrect to me, but thanks anyway)
I use setup_function, but I think it's similar. def setup_function(): db.drop_all_tables(with_all_data=True) db.create_tables() with db_session: # here you can set the data you need for the tests
Adam
Would Pony work well as the ORM for a many shaded discord bot? or would there be conflicts between shards?
Alexander
Would Pony work well as the ORM for a many shaded discord bot? or would there be conflicts between shards?
It should probably work well, but the sharding will not be teansparent for your application. You can create a separate db instance for each shard and initialize all of them with the same schema.
Alexander
Are there any problems with PR #671? Would be nice to have Python 3.11 compatibility, https://github.com/ponyorm/pony/pull/671
I'm sorry, before last weekend I fell off my bike and got a concussion, it slowed down the work on the release. I hope we can release it soon
Evan
I'm trying to change a name of a table in mysql - i was hoping to change the models.py file and simply run RENAME TABLE old_table TO new_table somehow through pony but not sure how to run this raw_sql command - if I run it inside a orm.select(orm.raw_sql(XX)) it didn't work - any ideas?
Alexander
I can suggest using some migrations manager which runs raw sql
Evan
ty
Evan
I'm trying to copy something from a mysql database to a postgres one - I have the models mysql.Table and postgres.Table and I tried to do something like t = mysql.Table[1] postgres.Table(**t) but this didn't work because t isn't a mapping, the definitions of Table are t he exact same and I've inherited from the right Entity class like in this question - is there an easy way to recreate the Table class?
Alexander
Not sure whats the problem you're trying to solve
Volbil
Or simply dump database data to json and import to postgres
Evan
Not sure whats the problem you're trying to solve
just to copy over data from one db to the other
Volbil
do you have any suggestions by any chance?
I’ve done such migration using json dump
Vitaliy
I’ve done such migration using json dump
Json is too slow if you have a lot of data, I recommend to use pickle instead
Alexander
I wonder if regular sql dump (which is actually tons of inserts) could work
Evan
just fyi it wasn't a huge db so I ended up just rewriting the read / insert code - but not ideal as I don't know if I've messed something up or not
Evan
is there an easy way to grant privileges to a postgres db through pony?
Alexander
Pony is a not a db management tool. You should do it manually
Evan
ok got it thank you
Noname
Hello everybody! Can you help me? I am working with pony for second day according to specs and official doc "getting started ". I have a problem, I don't get values with select function. I checked DB in pgAgent, and there values exist. Whole code is written from doc. Please, i am waiting for any advices🙏😔
Noname
Hello everybody! Can you help me? I am working with pony for second day according to specs and official doc "getting started ". I have a problem, I don't get values with select function. I checked DB in pgAgent, and there values exist. Whole code is written from doc. Please, i am waiting for any advices🙏😔
Noname
Hello everybody! Can you help me? I am working with pony for second day according to specs and official doc "getting started ". I have a problem, I don't get values with select function. I checked DB in pgAgent, and there values exist. Whole code is written from doc. Please, i am waiting for any advices🙏😔
Alexander
Hi, you're missing [:] at the end
Volbil
There is no pony object in response
Noname
Hi, you're missing [:] at the end
It is not working, forgot to add for this time
Alexander
He's working at the terminal, it doesnt require db_session
Noname
There is no pony object in response
I understand. This is my question, why ))
Noname
But if I do request to objects, it works correctly
Noname