Skip to content

matchaxnb/ponygen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Ponygen - a Pony ORM class generator

Ponygen generates classes from an information_schema database and a given schema.

It does not support what Pony does not support.

Preliminary notes

Basically this is a hack, a helper for developers and by no means code to be exposed in production.

Untested, just the minimal set of what I need. One hour of work or so.

Published to help other people trying to do the same thing.

Nice extras

To automatically register an extension class to your PonyORM classes, use mymodule.ponygen.ExtraClassFactory.register("MyClassName", my.module.MyOtherClass)

Table prefixes are supported. They are cleaned up at class generation and can be specified at bind time.

Example usage

python ponygen.py mysql://chloe:chloe@localhost/galette galette --engine=pymysql --outdir=./outdir/

will generate classes in outdir/

Then you have to write your __init__.py (an empty file does the job)

And then, do something like

from outdir.ponygen import init_mappings

from outdir.ponygen import init_mappings, ExtraClassFactory

class Fooza(object):
    def blahbli(self):
        return "lel"

ExtraClassFactory.register('Adherents', Fooza)

init_mappings(prefix='test_', engine='mysql', host='localhost', user='chloe', passwd='strongpass', db='galette')

from outdir.adherents import Adherents

b = [a for a in
Adherents.select()]

b[0]
>>> Adherents[1]

 b[0].blahbli()
>>> 'lel'

The main attention point is to run init_mappings after you have registered your extensions.

About

A class generator for PonyORM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages