library Module

The Library class, an sqlite database of cards.

class librarian.library.Library(dbname, cachelimit=100, cardclass=<class 'librarian.card.Card'>)

Bases: object

Library wraps an sqlite3 database that stores serialized cards.

Library also allows load and save hooks that allow a list of function to be called on each string as it is saved and loaded.

The Library constructor can take a cardclass argument which defaults to librarian.card.Card and is used to construct a card object when loading. A cardclass should be a subclass of librarian.card.Card and be able to take the original carddict constructor argument alone along with providing the original or equal Card.load and Card.save methods.

cache_card(card)

Cache the card for faster future lookups. Removes the oldest card when the card cache stores more cards then this libraries cache limit.

cached(code)

Return True if there is a card for the given code in the cache.

connection()

Connect to the underlying database and return the connection.

create_db()

Create the CARDS table in the sqlite3 database.

Return a list of codes and names pertaining to cards that have the given information values stored.

Can take a code integer, name string, abilities dict {phase: ability list/”*”}, attributes list, info dict {key, value list/”*”}.

In the above argument examples “*” is a string that may be passed instead of a list as the dict value to match anything that stores that key.

load_card(code, cache=True)

Load a card with the given code from the database. This calls each save event hook on the save string before commiting it to the database.

Will cache each resulting card for faster future lookups with this method while respecting the libraries cache limit. However only if the cache argument is True.

Will return None if the card could not be loaded.

retrieve_all()

A generator that iterates over each card in the library database.

This is best used in for loops as it will only load a card from the library as needed rather then all at once.

save_card(card, cache=False)

Save the given card to the database. This calls each save event hook on the save string before commiting it to the database.

librarian.library.Where_filter_gen(*data)

Generate an sqlite “LIKE” filter generator based on the given data. This functions arguments should be a N length series of field and data tuples.

Project Versions

Previous topic

API

Next topic

deck Module

This Page