Sqlite Integrated / Columns

Creating Databases in Python Nicely

After implementing queries i realized, that i now only need to write raw SQL when creating a new table. To fix this, and completely pythonify sqlite interaction, i now needed to implement a way to create a table in python.

This was quite simple: I made a class called Column that contained all the settings an Sqlite3 collumn could have. With this new class i could create a database method called create_table that takes a list of columns.

For representing foreign keys, i had make another simple class, that includes all the settings for a foreign key relationship.

This results in a very simple and nice way of creating tables:

db.create_table("people", [
    Column("id", "integer", primary_key=True),
    Column("first_name", "text"),
    Column("last_name", "text", not_null=True)
])