Anonymous
ok, damn, I. thought I could find a library that does it, but I would have never thought that you wrote that manually. really good job, looks very slick 👍
Alexey
Thank you so much!
Alexey
What are you trying to do? @marcno6
Anonymous
I am building an ORM as well, but in Typescript only, and I absolute fall in love with your schema-editor 🙂
Anonymous
Sure! I’m currently working on the site, so bear with me. https://beta.deepkit.io/products/orm. I also figured out how you did it using bézier curves and implemented it already, great idea 👍
Carel
@marcno6 I’m curios to know if your ORM would run server side on node.js ? Is there a possibility of it running client side (I get this is unlikely I just thought to ask) ?
Anonymous
It actually runs in the browser as well. The link I posted is a VSCode editor where you can play around with it.
Carel
Doesn’t that create a whole heap of issues e.g. network latency, requests/responses going awry, security woes ? Or is it all wrapped into an api ?
Anonymous
it uses SQLite in your browser, just for demonstration purposes
Anonymous
you’d use the ORM usually on the server of course 😛
Carel
Thanks, didn’t realize one had SQLite browser side. (Forgive my ignorance I don’t wander into the frontend too much).
Anonymous
you are right, you don’t have SQLite in the browser usually. It’s JS (wasm) version of SQLite, see https://github.com/sql-js/sql.js/
Carel
Ah, thanks.
Anonymous
Looking slick! Is there a git repo to this?
thanks! Github repo link is on the website🙏
Lucky
thanks! Github repo link is on the website🙏
Ah. Maybe the @deepkit/* things on the readme should be clickable?
Anonymous
It's all in the same repo under /packages, but good point😅
Lucky
Oh, I figured they'd be separate repos with that naming.
Lucky
But then I rarely use npm ^^'
Lucky
Ah, found it: https://github.com/deepkit/deepkit-framework/tree/feature/orm-browser/packages/orm-browser-gui
Permalink Bot
Ah, found it: https://github.com/deepkit/deepkit-framework/tree/feature/orm-browser/packages/orm-browser-gui
Permanent link to the file orm-browser/packages/orm-browser-gui mentioned. (?)
Anonymous
great job, Marc!
Thanks Alexey!
Christian
ponyorm.org Website Certificate seems to be expired? I'm getting a warning today, Firefox 85
Christian
Anonymous
same
Christian
I have a model field level = Required(int, default=0, size=8, unsigned=True) in a SQLite DB. When I update it with -1 from 0 I would expect it to remain 0, because of the unsigned (min/max) setting.
Christian
However, it becomes -1. Any pointers to where my mistake is?
Christian
And for which version is "updating multiple objects (bulk update)" planned? (Ref. to https://docs.ponyorm.org/working_with_entity_instances.html#updating-an-object)
Christian
I guess, because you cannot close the Database connection while you are possibly still transmitting. https://docs.ponyorm.org/api_reference.html#Database.disconnect
Christian
Are you trying to build the @db_session decorator on your own? Or am I misunderstanding your code?
Christian
Bottom of this section: https://docs.ponyorm.org/api_reference.html#db_session
Anonymous
i wanna close the connection when i have execute the db
Alexander
I suspect you have another @db_session which wraps your entire db_access function. You need to remove it
Konstantin
Excuse me, I can't find some information about that Is there any native support of postgres PostGis?
Alexander
No, Pony does not have native support for PostGis, but probably you can use raw sql queries and raw sql fragments for that
Konstantin
That is really sad(
Konstantin
Thanks for the reply
Alexander
As an experiment, you can add db.disconnect() before try:. If you will get the same exception on that line, then you somehow have outer db_session
Alexander
However, it becomes -1. Any pointers to where my mistake is?
Thank you for reporting, it was a bug, I fixed it on GitHub
Anonymous
Hi ! is there a way to dynamically order_by?
Volbil
Hi ! is there a way to dynamically order_by?
What do you mean by dynamically?
Anonymous
like im sending the order_by params in the url and then put it in the query. example: /api/products?order_by=price then Product.select().order_by(lambda p: p.price)
Anonymous
right now I added a nested if condition to handle the fields that I wanted to sort with
Anonymous
if sort: if sort == 'ratings': order_by = lambda p: desc(p.average_rating) if sort == 'price': order_by = lambda p: desc(p.price) if sort == 'shop': order_by = lambda p: desc(p.category.shop) products = Product.select(filters).order_by(order_by)[offset:10]
Anonymous
wondering if there was a cleaner approach
Volbil
You can do select and order query next
Volbil
query = Product.select(filters) if sort == 'ratings': query = query.order_by(desc(p.average_rating))
Volbil
Something like that
Anonymous
Thanks!
Alexander
It may be .order_by(lambda p: desc(p.average_rating)) or .order_by(desc(Product.average_rating))
El Mojo
I have a question, for an api I use fastapi / pydantic and pony. I am actually doing a prefetch of all related abjects before returning the response through pydantic models. Is there any other way to not prefetch objects before?
Alexander
I think it is not necessary to use prefetch if you set up db_session as a middleware, as it will be available through the entire request
El Mojo
i did that as a middleware but the session was ending most of the time prematurely
Alexander
I don't have a ready answer now, will think about it
El Mojo
thank you 🙂
Anonymous
Any way to order_by with desc using multiple fields ? i.e. I have a Product model that have a Stocks set and a Shop required FK. I'm trying to sort the Product and group each in the same shop while ordering them by Stock (highest to lowest)
Alexander
query = Product.select(...) # or select(p for p in Product if ...) query1 = query.order_by(desc(Product.field1), desc(Product.field2)) # or, if you want to order by arbitrary expressions: query2 = query.order_by(lambda p: (desc(p.field1), desc(p.field2))) # or in multiple steps: query3 = query.order_by(lambda p: desc(p.field2)) query3 = query3.order_by(lambda p: desc(p.field1)) # note that we first order by field2 and then by field1
Anonymous
thanks!
Anonymous
hi there. how to load cookies in requests session? cookies saved as cookies.pkl with pickle. help me please
Alexander
Hi. This group is about PonyORM object-relational mapper. It does not work with cookies. Probably is ts better to ask question in a group dedicated to a web framework that you use.
Christian
Can someone point me to an explanation, why in models default=datetime.datetime.utcnow works but default=datetime.datetime.utcnow() doesn't? The latter seems to always return the date of DB creation.
Jim
default takes a callable or detetime, si if you add () it gives you the datetime of db creation
Christian
Jim
https://docs.ponyorm.org/api_reference.html#cmdoption-arg-default
Christian
I think I'm getting it: utcnow() is called when the db is first created, setting the static datetime as the default on the first read, whereas the "built-in method" utcnow returns the time of the read/compile?
Christian
I'm just confused why the method has no () at the end whereas the static value does. What's the logic behind that? I'd have expected it the other way round.
Lucky
If you were to now call that function directly you would get a result. So you would get the following: default=datetime(year=2020, day=...) Because that's the result of calling daytime.now
Lucky
some other way to write the wrong case is this: now = datetime.now() class Table(...): date_column = Required(datetime, default=now)
Lucky
If you instead provides a method it can later call, pony Will do so when storing values to the database. It will then call whatever you specified to default=..., basically default()
Lucky
OK that was quite pieced together in multiple messages, I hope it helps anyway