X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fdb.py;h=ba091f3442286186c4cacb4de619f51078cb25cf;hb=991627dd1d4fcdecc04a091ec9c0c8b9e8e8b27c;hp=6e08204acfcdac30da1ec9790b2132d9e7d8df14;hpb=e024316d57d1b879bdedcc3c80d6583fd86a7b3c;p=m_librarian.git diff --git a/m_librarian/db.py b/m_librarian/db.py index 6e08204..ba091f3 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -2,7 +2,7 @@ __all__ = ['Author', 'Book', 'Extension', 'Genre', 'Language', 'AuthorBook', 'BookGenre', - 'init_db', 'insert_name', 'update_counters', + 'init_db', 'insert_name', 'insert_author', 'update_counters', ] import os @@ -157,6 +157,14 @@ def insert_name(table, name, **kw): return table(name=name, count=0, **kw) +def insert_author(surname, name, misc_name): + try: + return Author.full_name_idx.get( + surname=surname, name=name, misc_name=misc_name) + except SQLObjectNotFound: + return Author(surname=surname, name=name, misc_name=misc_name, count=0) + + def update_counters(): for author in Author.select(): author.count = len(author.books)