[PonyORM-list] show() not printing LongStr

Chris Wood c.c.wood at gmail.com
Thu Dec 11 10:12:54 UTC 2014


Hi Alexey,

Ah, that makes sense! Thanks for the explanation.

Chris

>
> Hi Alexey,
>
> thanks for the reply; I should have been clearer about when I was
> calling show()! I was trying to call it to show what data was in a
> table in my database:
>
>>>> from pony.orm import *
>>>> db = Database()
>>>> class Entity1(db.Entity):
> ...   attr1 = Required(LongStr)
> ...
>>>> db.bind('sqlite',':memory:')
>>>> db.generate_mapping(create_tables=True)
>>>> show(E1)
> class E1(Entity1):
>     id = PrimaryKey(int, auto=True)
>     attr1 = Required(LongStr)
>>>> test_data_entry = Entity1(attr1="test!")
>>>> data = select(p for p in Entity1)[:]
>>>> data.show()
> id
> --
> 1
>
> compared with
>
>>>> from pony.orm import *
>>>> db = Database()
>>>> class Entity2(db.Entity):
> ...   attr2 = Required(str)
> ...
>>>> db.bind('sqlite',':memory:')
>>>> db.generate_mapping(create_tables=True)
>>>> show(Entity2)
> class Entity2(Entity):
>     id = PrimaryKey(int, auto=True)
>     attr1 = Required(str)
>>>> test_data_entry= Entity2(attr2="test!")
>>>> data = select(p for p in Entity2)[:]
>>>> data.show()
> id|attr2
> --+-----
> 1 |test!
>
>
> It seems that the column which is defined as a LongStr isn't
> displayed, but one that is displayed as a str is?
>
> Chris
>
> Message: 2
> Date: Thu, 11 Dec 2014 01:44:27 +0300
> From: Alexander Kozlovsky <alexander.kozlovsky at gmail.com>
> To: Pony Object-Relational Mapper mailing list
>         <ponyorm-list at ponyorm.com>
> Subject: Re: [PonyORM-list] show() not printing LongStr (Alexey
>         Malashkevich)
> Message-ID:
>         <CAGM6z1s9mbm5Rm7aQuAUf+FpqnoCYpevMAWrYdqFxrhoJq0oxA at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Chris!
>
> This behavior is "by design". The LongStr type is intended for very long
> strings, such as the description of a product or the content of an article.
> We typically don't want to load such an attribute each time the object
> itself is loaded. Hence, LongStr attributes marked as "lazy" by default.
>
> The `show()` method of the query result does not display lazy attributes.
> Firstly, because such attributes are not loaded by default, and we don't
> want to send additional queries. And secondly, because the content of such
> attribute can be really large for displaying inside formatted table cell.
>
> If you truly want to display such an attribute, you have several options:
>
> 1) You can use `str` type instead of `LongStr` if the content of the
> attribute is not really large.
>
> 2) You can mark attribute as a non-lazy, if you want to load it with the
> typical query:
>
>     attr1 = Required(LongStr, lazy=False)
>
> Currently it is not possible to force the query to load lazy attributes
> along with the normal attributes. In the future we plan to add the way to
> explicitly load some lazy attributes with the query. After that the
> `show()` method probably should display such attributes along with the
> other attributes.
>
> Regards,
> Alexander Kozlovsky
>
>
> On Wed, Dec 10, 2014 at 10:56 PM, Chris Wood <c.c.wood at gmail.com> wrote:
>
>> Hi Alexey,
>>
>> thanks for the reply; I should have been clearer about when I was
>> calling show()! I was trying to call it to show what data was in a
>> table in my database:
>>
>> >>> from pony.orm import *
>> >>> db = Database()
>> >>> class Entity1(db.Entity):
>> ...   attr1 = Required(LongStr)
>> ...
>> >>> db.bind('sqlite',':memory:')
>> >>> db.generate_mapping(create_tables=True)
>> >>> show(E1)
>> class E1(Entity1):
>>     id = PrimaryKey(int, auto=True)
>>     attr1 = Required(LongStr)
>> >>> test_data_entry = Entity1(attr1="test!")
>> >>> data = select(p for p in Entity1)[:]
>> >>> data.show()
>> id
>> --
>> 1
>>
>> compared with
>>
>> >>> from pony.orm import *
>> >>> db = Database()
>> >>> class Entity2(db.Entity):
>> ...   attr2 = Required(str)
>> ...
>> >>> db.bind('sqlite',':memory:')
>> >>> db.generate_mapping(create_tables=True)
>> >>> show(Entity2)
>> class Entity2(Entity):
>>     id = PrimaryKey(int, auto=True)
>>     attr1 = Required(str)
>> >>> test_data_entry= Entity2(attr2="test!")
>> >>> data = select(p for p in Entity2)[:]
>> >>> data.show()
>> id|attr2
>> --+-----
>> 1 |test!
>>
>>
>> It seems that the column which is defined as a LongStr isn't
>> displayed, but one that is displayed as a str is?
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: </ponyorm-list/attachments/20141211/d4d30491/attachment-0001.html>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 11 Dec 2014 02:06:01 +0300
> From: Alexander Kozlovsky <alexander.kozlovsky at gmail.com>
> To: Pony Object-Relational Mapper mailing list
>         <ponyorm-list at ponyorm.com>
> Subject: Re: [PonyORM-list] Example with disconnect()
> Message-ID:
>         <CAGM6z1suS5rf89DBmmn+5VvDrC4UX815MYJVYPGYVpus=bhc2g at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Arthur!
>
> For what purpose do you want to use `disconnect` method? I'm not sure I
> correctly understand what example you want to see, but the simplest example
> of `disconnect` method is this:
>
>     from pony.orm import *
>
>     db = Database('mysql', host="myhost", user="me", passwd="123",
> db="mydb")
>
>     class Person(db.Entity):
>         name = Required(str)
>
>     db.generate_mapping(create_tables=True)
>
>     with db_session:
>         p1 = Person(name='John')
>
>     db.disconnect()
>
>
> The disconnect method works for current thread only. It releases connection
> to the server which db object holds in its connection pool.
>
> This method should be called outside of any db session.
>
> If you application is multi-threaded and you want to disconnect your db
> object from the database, the you need to call `disconnect` method from
> each thread in which you have worked with the entities of this db object.
>
>
> Regards,
> Alexander Kozlovsky
>
>
> On Wed, Dec 10, 2014 at 5:39 AM, Goldberg, Arthur P <
> arthur.p.goldberg at mssm.edu> wrote:
>
>>  Hi Guys
>>
>>  Could you please show an example with disconnect()? I'm using a couple
>> of dbmses in one SQL server, and getting
>>  Database object was already bound to MySQL provider
>> Sorry, I'm too rushed to debug carefully.
>>
>>  Yhanks
>> A
>>
>>
>>            ---
>>
>> Arthur Goldberg
>> Associate Professor of Psychiatry
>> Seaver Autism Center and Icahn Institute for Genomics & Multiscale Biology
>> Icahn School of Medicine at Mount Sinai
>>  Seaver Center, Room ABE-33
>>  212-241-4229
>> Arthur.Goldberg at mssm.edu
>>  Follow us on Twitter @IcahnInstitute <https://twitter.com/IcahnInstitute>
>>
>>
>>
>>
>>
>> _______________________________________________
>> ponyorm-list mailing list
>> ponyorm-list at ponyorm.com
>> /ponyorm-list
>>
>>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: </ponyorm-list/attachments/20141211/c9a870e0/attachment.html>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
> ------------------------------
>
> End of ponyorm-list Digest, Vol 16, Issue 5
> *******************************************


More information about the ponyorm-list mailing list