Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

StarUML extension to generate PeeWee database models

Purpose

The aim of this project is to provide an StarUML extension to:

  • Auto-generate Python PeeWee Model Classes from an Entity Relationship Diagram (ERD).

Installation

  1. Install StarUML, download page.
  2. Download or clone this repo.
  3. Copy repo files to StarUML extension user folder:
  • MacOS: ~/Library/Application Support/StarUML/extensions/user/staruml-peewee
  • Windows: C:\Users\<user>\AppData\Roaming\StarUML\extensions\user\staruml-peewee
  • Linux: ~/.config/StarUML/extensions/user/staruml-peewee

Usage

First create a ERD defining the database layout in StarUML. Then run this extension to translate that to a Python PeeWee Model corresponding to the same database schema which you have defined. Specifically,

  1. Click the menu (Tools > PeeWee Database Model > Generate Code...)
  2. If necessary, select a base model (or package) that will be generated to PeeWee database model.
  3. Select a folder where the generated Python source file (.py) will be placed.

Sample

#===============================================================================
# PeeWee Database Model
#===============================================================================


from peewee import *

db = SqliteDatabase('data.db')


#-------------------------------------------------------------------------------


class BaseModel(Model):

    class Meta:
       database = db


#-------------------------------------------------------------------------------



class Good(BaseModel):
    """A good is something which you can make or buy"""
    name = CharField(unique = True)
    baseValue = IntegerField()



class Recipe(BaseModel):
    name = CharField(max_length = 80)
    amountProduced = IntegerField()
    product = ForeignKeyField(Good)



class Ingredients(BaseModel):
    amount = IntegerField()
    good = ForeignKeyField(Good)
    recipe = ForeignKeyField(Recipe, backref = "ingredients")

Disclaimer

This project is provided as-is, with no implied warranty of any kind. This is very much a work-in-progress. Feel free to report any bugs that you find here via github.

Contributors

This project is based on a similar project, staruml-django, by josemlp91.

If you find this useful, feel free to buy me a coffee.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages