DBIS Schema Creator
Create a schema for SQLite databases and populate it using object-oriented programming. Also draw the corresponding er-diagram.
Installation
pip install dbis-schema-creator
Usage
from schema_creator import *
from erdiagram import ER
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 = ER()
g.add_node("User")
g.add_attribute("User", "user_id", isPK=True)
g.add_attribute("User", "username")
return g
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 = ER()
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)
return g
# 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.draw()
digraph.render('er-diagram', format='png', view=True)
Metadata
Release files for dbis-schema-creator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dbis-schema-creator-0.1.0.tar.gz | 6.4 kB | Without provenance | Details for dbis-schema-creator-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dbis_schema_creator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for dbis_schema_creator-0.1.0-py3-none-any.whl |
Total release size: 11.4 kB
Release files / dbis-schema-creator-0.1.0.tar.gz
| Download URL | dbis-schema-creator-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70ade58565ed8efb3e8f589c31f7cdd282c30b3008d61099d6ce62ba4443e597
|
|
BLAKE2b-256 checksum How to use checksums |
bd48093927821074ded4b1a3d007d64113e82b065d25dccff99aeaf4047197a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / dbis_schema_creator-0.1.0-py3-none-any.whl
| Download URL | dbis_schema_creator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de7a9740e2e39c96c31be0f2702d1603c0f66dad66597fdc1754f19677ab719b
|
|
BLAKE2b-256 checksum How to use checksums |
84f0795ecfb40d87a41805e22a8eb3f2c15b8ef941081a8a87695875dc340d4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for dbis-schema-creator 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.