[PonyORM-list] pony entities in multiple modules

Goldberg, Arthur P arthur.p.goldberg at mssm.edu
Thu Nov 6 03:18:35 UTC 2014


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<mailto:Arthur.Goldberg at mssm.edu>>
 wrote:


On Nov 5, 2014, at 1:29 PM, Arthur Goldberg <Arthur.Goldberg at mssm.edu<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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<mailto: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<mailto:Arthur.Goldberg at mssm.edu>
Follow us on Twitter @IcahnInstitute<https://twitter.com/IcahnInstitute>




-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141106/0d333dc4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theDB.py
Type: text/x-python-script
Size: 116 bytes
Desc: theDB.py
URL: </ponyorm-list/attachments/20141106/0d333dc4/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geneticsClasses.py
Type: text/x-python-script
Size: 8957 bytes
Desc: geneticsClasses.py
URL: </ponyorm-list/attachments/20141106/0d333dc4/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geneticsDBMScommon.py
Type: text/x-python-script
Size: 1912 bytes
Desc: geneticsDBMScommon.py
URL: </ponyorm-list/attachments/20141106/0d333dc4/attachment-0005.bin>


More information about the ponyorm-list mailing list