diff options
author | Camil Staps | 2015-10-04 14:31:38 +0200 |
---|---|---|
committer | Camil Staps | 2015-10-04 14:54:10 +0200 |
commit | 5ea8db32ef9d5f788b854e82248cf62316ed0120 (patch) | |
tree | 7f9e9992ec40f1017019cac02cf67c6ee27fc0c0 /pyble.py | |
parent | Script to read Bible Hub database; Readme (diff) |
Orator, Click
Diffstat (limited to 'pyble.py')
-rw-r--r-- | pyble.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/pyble.py b/pyble.py new file mode 100644 index 0000000..b399a29 --- /dev/null +++ b/pyble.py @@ -0,0 +1,88 @@ +from orator import DatabaseManager, Model, Schema + +class Part(Model): + __timestamps__ = False + __fillable__ = ['name'] + +class Book(Model): + __timestamps__ = False + __fillable__ = ['canonical_name'] + +class Verse(Model): + __timestamps__ = False + __fillable__ = ['book', 'chapter', 'nr'] + +class Translation(Model): + __timestamps__ = False + __fillable__ = ['name'] + +class TranslatedVerse(Model): + __timestamps__ = False + __table__ = 'translated_verses' + __fillable__ = ['translation', 'book', 'chapter', 'nr', 'text'] + +class Passage(Model): + __timestamps__ = False + __fillable__ = ['fst', 'snd'] + +class CrossReference(Model): + __timestamps__ = False + __fillable__ = ['passage_id1', 'passage_id2', 'relevance'] + +def setup_tables(db): + schema = Schema(db) + + with schema.create('parts') as table: + table.string('name') + table.primary('name') + + with schema.create('books') as table: + table.string('canonical_name').primary() + + with schema.create('verses') as table: + table.string('book') + table.small_integer('chapter') + table.small_integer('nr') + table.foreign('book').references('canonical_name').on('books') + table.primary(['book', 'chapter', 'nr']) + + with schema.create('translations') as table: + table.string('name').primary() + + with schema.create('passages') as table: + table.increments('id') + table.string('fst_book') + table.small_integer('fst_chapter') + table.small_integer('fst_nr') + table.string('snd_book') + table.small_integer('snd_chapter') + table.small_integer('snd_nr') + table.foreign(['fst_book', 'fst_chapter', 'fst_nr'])\ + .references(['book', 'chapter', 'nr']).on('verses')\ + .on_delete('restrict').on_update('cascade') + table.foreign(['snd_book', 'snd_chapter', 'snd_nr'])\ + .references(['book', 'chapter', 'nr']).on('verses')\ + .on_delete('restrict').on_update('cascade') + table.unique(['fst_book', 'fst_chapter', 'fst_nr', + 'snd_book', 'snd_chapter', 'snd_nr']) + + with schema.create('crossreferences') as table: + table.integer('passage_id1') + table.integer('passage_id2') + table.small_integer('relevance').default(0) + table.foreign('passage_id1').references('id').on('passages') + table.foreign('passage_id2').references('id').on('passages') + table.primary(['passage_id1', 'passage_id2']) + + with schema.create('translated_verses') as table: + table.string('translation') + table.string('book') + table.small_integer('chapter') + table.small_integer('nr') + table.string('text') + table.foreign('translation').references('name').on('translations') + table.foreign(['book', 'chapter', 'nr'])\ + .references(['book', 'chapter', 'nr']).on('verses')\ + .on_delete('restrict').on_update('cascade') + table.primary(['translation', 'book', 'chapter', 'nr']) + |