RWTH Aachen Computer Science i5/dbis assets for Lecture Datenbanken und Informationssysteme
Project description
DBIS Schema Creator
Create a schema for SQLite databases using object-oriented programming. Also draw the corresponding er-diagram.
Installation
pip install dbis-schema-creator
Usage
from schema_creator import *
from faker import Faker
fake = Faker()
# Create a Table object (sqlalchemy style)
class Users(Table):
# Create tables
user_id = Column(Integer, primary_key=True)
username = Column(String(50))
# Optionally set the table name. Default is the lowercase class name
__tablename__ = 'users'
# Specify how to populate the table (e.g., using faker or random)
def populate(session, seed=None):
for _ in range(100):
user = Users(username=fake.name())
session.add(user)
# Specify how to draw the er-diagram
def to_er_diagram(g):
g.add_node("User")
g.add_attribute("User", "user_id", isPK=True)
g.add_attribute("User", "username")
class Posts(Table):
post_id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.user_id'))
text = Column(String(1000))
depedencies = {Users} # specify the tables that this table depends on. Default is none
def populate(session, seed=None):
# get already populated user table
users = session.query(Users).all()
for _ in range(1000):
user = random.choice(users)
post = Posts(user_id=user.user_id, text=fake.text())
session.add(post)
def to_er_diagram(g):
g.add_node("Post", isWeak=True)
g.add_attribute("Post", "post_id", isPK=True, isWeak=True)
g.add_attribute("Post", "user_id")
g.add_attribute("Post", "text")
g.add_relation("User", "posts", "Post", "1", "m", isWeak=True)
# Create the schema factory
tables = {Users, Posts}
factory = SchemaFactory(tables)
# populate the table
factory.populate()
# create the schema
schema = factory.to_sql()
# create the er-diagram
er_diagram = factory.to_er_diagram()
# draw the er diagram
digraph = er_diagram.graphViz
digraph.format = 'png'
digraph.render('er-diagram', view=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for dbis-schema-creator-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f9eb861c266fab67898edea6cf6bbe7c85ebfe312bf0daff2ef6bff53a6c64e |
|
MD5 | aa0b8e6289b396b0b53bbe275fc41cb9 |
|
BLAKE2b-256 | a0b3ebc6c84cf57c179c2779bace354144da4236953681bafea226710a113d96 |
Close
Hashes for dbis_schema_creator-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 111cf7b57ec1f3930649ac2c8d468127cff58d8655412c04fe5977c0ad25749c |
|
MD5 | 4b51fda17fa6967ae65043e8a64287d5 |
|
BLAKE2b-256 | 96d13a2455e6e6fa618f1b42992152d4c0408abfa296ca9d5464c22623534eda |