@ponyorm

Страница 50 из 75
Teno
03.12.2017
09:26:28
I mean python and Django history

Yuri
03.12.2017
09:29:13
If so, then I would like to know this history.

Alexander
03.12.2017
10:06:01
I think Teno refers to the Django mascot: http://www.djangopony.com/ https://stackoverflow.com/questions/2115360/what-is-the-deal-with-the-pony-in-python-community In fact, we chose a name for the library before the theme with a Django-pony mascot started, and were very surprised when Django developers began to use pony in its image. We decided to use the name PonyORM for the following reasons: - Ponies are small, smart and strong, just like our library: PonyORM is small (easy to use, easy to install, doesn't depend on other libraries, has intuitive API), smart (make various automatic query optimizations) and powerful (can be used for very advanced applications with complex queries) - Our goal is that working with PonyORM should be as easy and enjoyable as playing with Pony - PonyORM has pretty big amount of "magic" inside, just like some ponies - The name starts with "P" (a popular choose for Python libraries) and "Pony ORM" phrase did not appear in Google search results, so was good from SEO point of view - We don't want to appear too "serious" and "pretentious". Actually, Python language itself was called after a comedy show, so why not to use some silly name for the Python library - Actually, we wanted to initially position Pony as a toy. It is not necessary a bad. Paul Graham wrote: "Don't be discouraged if what you produce initially is something other people dismiss as a toy. In fact, that's a good sign. That's probably why everyone else has been overlooking the idea. The first microcomputers were dismissed as toys. And the first planes, and the first cars. At this point, when someone comes to us with something that users like but that we could envision forum trolls dismissing as a toy, it makes us especially likely to invest."

Teno
03.12.2017
10:12:35
I agree 100%

Google
Alexander
03.12.2017
10:13:39
We do not want our library to be perceived by users as something difficult to use. Our goal is that the learning curve be as flat as possible. The user can easily start to make simple examples and use Pony for simple tasks, and then gradually realize that for complex tasks the Pony is as good as for simple tasks. That is, the library is simple in appearance, but has a great depth and potential. It's somewhat similar to ponies :)

Luckydonald
03.12.2017
10:55:57
Why "Pony"?
Because Friendship is Magic.

Actually I have no clue.

Yuri
03.12.2017
12:32:55
Thanks, that is interesting. But why actually I am here. I`m writing a smal(or even middle) site using Flask. And I need an ORM. After a long hours of reading advantages and disatvantages of each orm I desided, that Python have two major ORM - SQLAlchemy and PonyORM. For me, SQLAlchemy isn`t very convenient compared to PonyORM. But SQLAlchemy have big comunity and is very popular. What do you think about it? What are the advantages or disadvantages of each of this ORM?

Alexander
03.12.2017
14:10:54
1) Query syntax: When you write a query with SQLAlchemy you basically write in some Python-based "dialect" of SQL. The Python->SQL translation process is relatively straightforward. You need to imagine correct SQL query first, and then write it using SQLALchemy syntax. But sometimes you can wonder, "if I need to know final SQL query anyway, why I need write some contrived Python version of it instead of writing SQL directly?" The benefit of using SQLAlchemy query engine is, you can use the same query with different databases, if that is important to you. More important benefit is, if you add some new column to a table, you don't need to manually add it to SELECT part of all queries. With Pony you describe the meaning of a query using generator syntax, and Pony translates it to most efficient SQL (the specific SQL may be different for different databases). There are several benefits of it: - Queries written using Pony feels very "native" and concise. The query language is more high-level than SQL, and very often a query in Pony looks shorter and cleared tnen the resulted correct SQL query. - You can write efficient queries even if you don't remeber the details of SQL syntax, you need to just write a semantically correct Python generator There is also several drawbacks: - Sometimes developer already knows the final SQL query he wants to get, but cannot figure out the correct Pony syntax. In this case he need to search for documentation, do some trial & error attempts, and fially ask me. After he sees the correct Pony syntax, he typically exclaims: "ah, this is so simple!" But, initially it may be not always very intuitive, because the syntax may be very different from SQL. - There are still some SQL queries for which Pony does not have API or cannot translate, like UNION queries or using some database specific functions. In many such cases it is possible to raw SQL queries or raw SQL fragments. Pony has a great support of raw SQL fragments, you can embed into high-level generators to write some specific SQL expression which Pony doesn't know about yet.

2) Using existing databases Sometimes you write a new application and create database schema from scratch. In other cases you conect to already existing database. With Pony, it is really easy to define a models (which are called entities in Pony terminology) and create a new database from them. But if you already have a database, it may require more work, because you will need to specify column and table names when defining entities. SQLAlchemy have a more advanced support for existing databases, and can reate models automatically using database reflexion. Pony recently too got a similar tool, but it was not tested for complex situations, like, composite primary keys, etc. The goal of SQLAlchemy is to support any crasy database schema in Python. The goal of Pony is to model information using Entity-Relationship approach, and to create a database schema which is best suited for given ER-diagram.

3) Schema evolution After the application is launched it is often required to modify models, for example to add new attributes. The best way to do this is to use some migration tool. SQLAlchemy has such a tool, called Alembic, and Pony doesn't have an official migration tool yet, although you can see preview version here: https://github.com/ponyorm/pony/tree/orm-migrations

4) Session management When you are working with database, you need to use transactions in order to avoid data corruption when multiple processes work with the same database at the same time. In order to working with transactions SQLAlchemy and Pony provides the concept of sessions. A session manage transactions and have associated cache of object loaded into memory. Internally the implementation of sessions in Pony and in SQLAlchemy looks similar. But the public API is diferent. In SQLAlchemy you are typicall working with sessions explicitly: you need to create a session and asociate objects with them, while in Pony sessions are managed implicitly, using with db_session context manager and @db_session decorator. The approach of SQLAlchemy is more flexible, but the API is more heavyweight. In typical web application, explicit session management is unnecessary, and I like Pony approach more.

5) Supported application types There are different types of applications which are working with database. One type is web application, where the goal is to serve HTTP request as fast as possible: fetch data from the database, generate HTML or JSON response and return it to the user. Pony is designed for that scenario and should be very efficient here. In that scenario, you typically want to retrieve as few data from the database as possible in order to work efficiently. Typically, one HTML page may require at most several thousand objects from the database. Another kind of application is when you retrieve millions of objects in a single session. In that case, it is not always possible to keep all these objects cached into memory, because it may reqire multiple gygabytes of RAM. SQLAlchemy has a way to fetch objects in batches and then expunge them from the cache manually, and Pony currently lacking such features, because that is not a scenary Pony was designed for. Pony has a good syntax support for aggregated queries, but Pony works better if the number of retrieved rows is counted in thousands, not millions.

6) New features Sometimes are developer extremely need some feature, and the ORM is not implemented that feature yet. With SQLAlchemy you can try do implement this feature itself, but with Pony you probably need to ask the development team. If the feature is very easy, sometimes we can implement it right away, but more complex features will be placed in queue and may require a long time to be implemented. For example, right now we are working on two big features: hybrid methods and properties (which can be used inside queries and will be translated to SQL) and migration tool, so another requested features will be postponed

Matthew
03.12.2017
14:14:07
Make the above into a blog post :)

Alexander
03.12.2017
14:14:38
Yes, I probably should :)

Yuri
03.12.2017
19:32:43
Wow. It`s pretty good explanation. Thanks a lot. :)

Google
Chukwudi
03.12.2017
19:50:11
@akozlovsky You are doing a huge job here. Well done

Alexander
03.12.2017
19:50:29
Thanks

Chukwudi
03.12.2017
19:50:58
Thanks
Do you know if Web2py DAL?

Alexander
03.12.2017
19:51:16
Never used it

Chukwudi
03.12.2017
19:51:30
Eugene
05.12.2017
16:59:17
Hi guys

Is far as I remember pony was proprietary some time ago, wasn't it?

Yuri
05.12.2017
17:13:07
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate It`s here.

Bonbot
05.12.2017
17:13:10
https://github.com/ponyorm/pony/tree/orm-migrations/pony/migrate It`s here.
Permanent link to the file pony/migrate mentioned. (?)

Alexey
05.12.2017
18:01:39
Is far as I remember pony was proprietary some time ago, wasn't it?
Hey Eugene, It wasn’t proprietary, the code was open from the very beginning. Initially we were distributing Pony ORM under dual license - AGPL and a commercial one. Later we changed the license to Apache 2.0. This license allows the user the freedom to use Pony for any purpose, distribute, modify, and to distribute modified versions of it. Free as in beer.

Alexander
05.12.2017
18:06:49
Is there already documentation out there? Or example code? Just the branch itself isn't a good entry point :D
The migration subpackage has short readme description, we'll extend it with more information

Juan
05.12.2017
18:20:54
Are you the famous nigerian prince from the emails?

Eugene
05.12.2017
18:21:33
Lol

Chukwudi
05.12.2017
18:26:07
Are you the famous nigerian prince from the emails?
Hell no. I'm a Python Programmer with over 12 year experience

Juan
05.12.2017
18:26:17
:P

Eugene
05.12.2017
18:26:36
but... your name...

Chukwudi
05.12.2017
18:27:03
I'm the chairperson of Python Nigeria Community, registered with the Nigerian body meant for such

I'm a PSF member with voting rights and I also serve at the Grants committee level

Google
Chukwudi
05.12.2017
18:27:54
I'm Chukwudi Nwachukwu

Eugene
05.12.2017
18:27:57
What is PSF?

Chukwudi
05.12.2017
18:28:36
https://ng.linkedin.com/in/ichux

Python Software Foundation

Eugene
05.12.2017
18:28:53
Oh

Chukwudi
05.12.2017
18:29:37
Are you the famous nigerian prince from the emails?
So, when I said I'll donate, I mean every part of it.

Juan
05.12.2017
18:30:13
It was a simple joke ?

Chukwudi
05.12.2017
18:30:21
I don't involved in any illegal activities. I have my name and image to protect @Mancuerna

It was a simple joke ?
Indeed, but it's a stark reality of what obtains in this part of the world

Alexander
05.12.2017
18:32:30
Chukwudi, I'm sorry if some replies were unappropriate. I think the guys just wanted to make a joke. We are greatly appreciate your participation in this chat!

Chukwudi
05.12.2017
18:33:46
I have loved pony from the day 1. Another one is Whoosh and SQLAlchemy

I'm active in those places too

But I just watch and contribute less

Alexey
05.12.2017
18:35:27
Talking about donations - actually we’d like to add such a possibility to the site. What options are there besides PayPal donate button? They say PayPal can lock an account at any time without any explanation...

Chukwudi
05.12.2017
18:36:55
Talking about donations - actually we’d like to add such a possibility to the site. What options are there besides PayPal donate button? They say PayPal can lock an account at any time without any explanation...
PayPal doesn't work well for us here. But I can send, only that I can't receive. Talk of one challenge we face here cos of the *famous Nigerian princes*

Eugene
05.12.2017
18:39:52
you know, it is something like "russians with bear and vodka" or "ukrainians with lard and revolutions"

Google
Alexander
05.12.2017
18:41:50
Oops, I forgot to feed my bear today, and there is nothing except vodka in my fridge

Chukwudi
05.12.2017
18:42:19
But are there other options to receive donations, other than PayPal?
Right now, unless I ask around, I can't really answer yes. I'm speaking as a Nigerian living here. But of course, there are other ways for other countries

Alexander
05.12.2017
18:43:30
Don't fear, it a small one

Actually, SQLAlchemy and other libraries like MobX use PayPal for donations. But there are many horros stories over the internet that PayPal can appropriate money from the account at any time, justifying it that the donations via PayPal are possible for specially registered non-profit organizations only, not for personal accounts and commercial organizations.

Henri
05.12.2017
18:57:35
Hmm never heard that. Using PayPal for donations and it's ok. Beside that the fee especially for small donations is quite big.

BTW I also have a bear running here around and he's quite big... and wild

Chukwudi
05.12.2017
18:59:47
Don't fear, it a small one
Waoh! I only see it on Satellite channels

Henri
05.12.2017
19:00:43
(Polish Carpathian mountains near Ukraine)

Alexander
05.12.2017
19:01:32
I was joking, but maybe Henri is serious :)

Chukwudi
05.12.2017
19:01:58
Henri
05.12.2017
19:02:20
Yep I am! ?

But no need to feed him.

Chukwudi
05.12.2017
19:05:21
But no need to feed him.
I guess it feeds around the mountain

Alexey
05.12.2017
19:05:29
Henri
05.12.2017
19:12:02
Do you use it as a personal account or an organization one?
Personal account but upgraded to business account (free).

I guess it feeds around the mountain
Actually soon should go to take his winter sleep as we already have deep snow all around.

Google
Chukwudi
05.12.2017
19:16:59
Actually soon should go to take his winter sleep as we already have deep snow all around.
Please send me pictures of it, privately, if you're able to.

Henri
05.12.2017
19:20:41
Please send me pictures of it, privately, if you're able to.
I mostly see only his foot steps :) But a friend of mine is wild animal photographer. So maybe I can ask him.

Chukwudi
05.12.2017
19:27:02
Dear admin, I could donate up-to $1000, but I doubt if there's a means for me to do such now. I plan relocating to a Western country next year, all other things being equal. I should be able to do such easily then. Thanks

Luckydonald
05.12.2017
19:47:02
Ok, i should program an orm too xD

Bjorn
07.12.2017
11:55:24
Hi - I might be having a brain meltdown, but I am convinced that this should work: with orm.db_session: g1 = orm.select(ol for ol in db.Orderline if ol.qty >= 3) orm.show(g1) # works g3 = orm.select(ol for ol in db.Orderline if ol.qty <= 5) orm.show(g3) # works. g4 = orm.select(ol for ol in g1 if ol.qty <= 5) orm.show(g4) # typeError? But pony throws the exception in g4: TypeError: Cannot iterate over non-entity object

I can achieve the goal (in g4) using g1.filter(lambda ol: ol.qty >= 5), but that's not so pretty I guess...?

My thinking is that it seems less pythonic to having to use filter and lambdas, rather than passing the previous query object in (g1).

Matthew
07.12.2017
12:07:46
I don't think it's possible unless you do g4 = orm.select(ol for ol in db.Orderline if ol.qty <= 5 and ol in g1)

Alexander
07.12.2017
12:10:30
I agree that we need to support select(x for x in <query>) too, it will be more intuitive to build query step-by-step this way. We just have no time to implement it yet. In the future we will add it for sure

Bjorn
07.12.2017
12:11:30
Right now I'm laughing my buts off. This actually works too: def gen(query): for i in query[:]: yield i g5 = list(ol for ol in gen(g1) if ol.qty <= 5) orm.show(g5)

Страница 50 из 75