From: Oleg Broytman Date: Thu, 24 Dec 2015 15:13:02 +0000 (+0300) Subject: Add indices X-Git-Tag: 0.0.3~3 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=e94c6883c5c71b05b82db32583cb05dac4091907;p=m_librarian.git Add indices --- diff --git a/m_librarian/db.py b/m_librarian/db.py index c77e32f..98e541e 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -1,12 +1,12 @@ #! /usr/bin/env python __all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language', - 'init_db', 'insert_name', + 'init_db', 'insert_name', 'update_counters', ] import os from sqlobject import SQLObject, StringCol, UnicodeCol, IntCol, BoolCol, \ - ForeignKey, DateCol, RelatedJoin, \ + ForeignKey, DateCol, DatabaseIndex, RelatedJoin, \ connectionForURI, sqlhub, SQLObjectNotFound, dberrors from .config import ml_conf @@ -54,6 +54,7 @@ if connection.dbName == 'sqlite': class Author(SQLObject): name = UnicodeCol(unique=True) count = IntCol() + count_idx = DatabaseIndex('count') books = RelatedJoin('Book', otherColumn='book_id') @@ -71,23 +72,27 @@ class Book(SQLObject): extension = ForeignKey('Extension') date = DateCol() language = ForeignKey('Language') + archive_file_idx = DatabaseIndex('archive', 'file', unique=True) class Extension(SQLObject): name = StringCol(unique=True) count = IntCol() + count_idx = DatabaseIndex('count') class Genre(SQLObject): name = StringCol(unique=True) title = UnicodeCol() count = IntCol() + count_idx = DatabaseIndex('count') books = RelatedJoin('Book', otherColumn='book_id') class Language(SQLObject): name = StringCol(unique=True) count = IntCol() + count_idx = DatabaseIndex('count') def init_db():