[PonyORM-list] pony entities in multiple modules

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Thu Nov 6 23:24:14 UTC 2014


Hi Arthur!

I think that I understand now what is the problem that you want to solve.

I just make some example repository which you can find useful. This
repository represents a basic example of how PonyORM-based project with
many entities can be organized. It contains several modules:

  * `base_entities.py` - defines `db` object and some common entities;
  * `forum_entities.py` - defines some additional entities;
  * `university_entities.py` - defines some additional entities;
  * `all_entities.py` - collect all entities together;
  * `db_settings.py` - define parameters to connect to the database;
  * `db_utils.py` - define function which connect to the database;
  * `db_loading.py` - populating some initial data;
  * `main.py` - the main program.

You can find the repository on GitHub:
https://github.com/kozlovsky/ponymodules
I also attached all files right to this message

Actually, it is very similar to the structure that you suggest in your last
messages. But maybe you will find some new ideas here.

Regards,
Alexander Kozlovsky


On Thu, Nov 6, 2014 at 6:18 AM, Goldberg, Arthur P <
arthur.p.goldberg at mssm.edu> wrote:

>  Here's one possible solution:
> 1) make a singleton database handle, as in theDB.py:
>   2) use the one handle everywhere it's needed, as in geneticsClasses.py:
>   3) also use the handle in the connect() function,
> in geneticsDBMScommon.py:
>   4) query programs then use the dbms entity classes
> and geneticsDBMScommon, basically like this:
>
>   #!/usr/bin/env python
>
>  from pony.orm import *
> import sys, os
> import argparse
>
>  from geneticsDBMScommon import *
> from geneticsClasses import *
>
>  def parseArgs( ):
>     parser = argparse.ArgumentParser(description="""Analyze variants""" )
>     parser.add_argument('DBMS', type=str, help="key for the DBMS, an index
> into the access params in DBMScreds" )
>     args = parser.parse_args()
>     return args
>
>  args=parseArgs()
> Connect( args.DBMS, debug=True )
>
>  o o o
>
>
>
>  On Nov 5, 2014, at 1:46 PM, Arthur Goldberg <Arthur.Goldberg at mssm.edu>
>  wrote:
>
>
>  On Nov 5, 2014, at 1:29 PM, Arthur Goldberg <Arthur.Goldberg at mssm.edu>
>  wrote:
>
>  Hello Alexander
>
>   let me be more specific.
>  I have a number of modules that query, update, delete against the
> database.
>  I want to centralize all the database bind, mapping,  and table deletion
> operations in one module that other modules can call.
>  Here's my effort to write that centralized module.
>  The only method is:
> Connect( DBMS='arthur_minerva', entityNames=[], dropAndCreateTable=False,
> debug=False )
> DBMS is simply a key into a dictionary of database credential parameters.
> That works fine, and is used by bind.
> entityNames is a list of entities;  I want to connect() to make sure that
> if an  entity is declared as a pony db  entity then it is in the database
> dropAndCreateTable  controls whether tables are dropped; if it is true
> then tables for all entities should be dropped and then created
>
>   with the call:
>  Connect( MyDropAndCreateTables.args.DBMS, entityNames='CNV
> Subject'.split(),
>             dropAndCreateTable=True, debug=True )
>   this does not work, however:
>
>    it generates this error:
>  b4 db.bind
> GET NEW CONNECTION
> RELEASE CONNECTION
> db.bind
> b4 db.generate_mapping
> GET CONNECTION FROM THE LOCAL POOL
> SET foreign_key_checks = 0
> COMMIT
> SET foreign_key_checks = 1
> CLOSE CONNECTION
> db.generate_mapping
> entity: CNV
> entityObj: <class 'geneticsClasses.CNV'>
> geneticsDBMScommon.pyc: WARNING: Pony MappingError: Database object is not
> bound with a provider yet
> geneticsDBMScommon.pyc: WARNING: Cannot drop_table()
>
>
>
>  I am using mysql.
>
>  On Nov 4, 2014, at 4:39 PM, Alexander Kozlovsky <
> alexander.kozlovsky at gmail.com> wrote:
>
> Hi Arthur,
>
> > How can I have the general purpose programs load all the pony entities,
> but then use only those specified on a command line?
>
> What do you mean by 'use'? Why this general purpose program can't use all
> entities? Can you provide some example?
>
>
> On Wed, Nov 5, 2014 at 12:24 AM, Goldberg, Arthur P <
> arthur.p.goldberg at mssm.edu
> <https://urldefense.proofpoint.com/v2/url?u=http-3A__mailto-3Aarthur.p.goldberg-40mssm.edu&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=-l9d_YgpS5Br4HVerevDUPDePIdahRQvh6kua6GEKCg&s=8BLVACjagdDyNx90SlAn1F7tsSllEw4K5MHFxb6KM1o&e=>
> > wrote:
>
> Hi Guys
>
> I've pony entities (class foo(db.Entity), etc.) definitions in multiple
> modules. And I've several general purpose programs: 1) connect to the dbms
> and optionally create tables, 2) load a file into a table, etc.
> How can I have the general purpose programs load all the pony entities,
> but then use only those specified on a command line?
>
> Is this clear?
>
> thanks
> Arthur
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
> <https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman-2Dmail5.webfaction.com_listinfo_ponyorm-2Dlist&d=AAMFaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=-l9d_YgpS5Br4HVerevDUPDePIdahRQvh6kua6GEKCg&s=ZTWdoePYiHrdwy3YThpUs2-mmvop7hGq2ibwteX9CYA&e=>
>
>
>  _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__mailman-2Dmail5.webfaction.com_listinfo_ponyorm-2Dlist&d=AAIGaQ&c=4R1YgkJNMyVWjMjneTwN5tJRn8m8VqTSNCjYLg1wNX4&r=TntoeYH7lekXzpBRjXwLTkqiWTbWAvp3pHKo_kZp5qI&m=-l9d_YgpS5Br4HVerevDUPDePIdahRQvh6kua6GEKCg&s=ZTWdoePYiHrdwy3YThpUs2-mmvop7hGq2ibwteX9CYA&e=
>
>
>         ---
>
> 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>
>
>
>
>
>   <geneticsDBMScommon.py><geneticsSubjects.py>
>
>
>         ---
>
> 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>
>
>
>
>
>
>         ---
>
> 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/20141107/34fc90d8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ponymodules.zip
Type: application/zip
Size: 29249 bytes
Desc: not available
URL: </ponyorm-list/attachments/20141107/34fc90d8/attachment-0001.zip>


More information about the ponyorm-list mailing list