def add_items(self, items): if not items: return logger.info("batch %s: adding %d items", self.name, len(items)) already_present = [row.ia_id for row in db.query("SELECT ia_id FROM import_item WHERE ia_id IN $items", vars=locals())] # ignore already present items = list(set(items) - set(already_present)) logger.info("batch %s: %d items are already present, ignoring...", self.name, len(already_present)) if items: values = [dict(batch_id=self.id, ia_id=item) for item in items] db.get_db().multiple_insert("import_item", values) logger.info("batch %s: added %d items", self.name, len(items))
def setup_method(self): self.db = get_db() self.db.multiple_insert("bookshelves_books", self.READING_LOG_SETUP_ROWS) self.db.multiple_insert("booknotes", self.BOOKNOTES_SETUP_ROWS) self.db.multiple_insert("ratings", self.RATINGS_SETUP_ROWS) self.db.multiple_insert("observations", self.OBSERVATIONS_SETUP_ROWS)
def setup_method(self, method): self.db = get_db() self.source_book = { "username": "******", "work_id": "1", "edition_id": "1", "bookshelf_id": "1", } assert not len(list(self.db.select("bookshelves_books"))) self.db.insert("bookshelves_books", **self.source_book)
def setup_class(cls): web.config.db_parameters = dict(dbn="sqlite", db=":memory:") db = get_db() db.query(""" CREATE TABLE bookshelves_books ( username text NOT NULL, work_id integer NOT NULL, bookshelf_id INTEGER references bookshelves(id) ON DELETE CASCADE ON UPDATE CASCADE, edition_id integer default null, primary key (username, work_id, bookshelf_id) );""") db.query( """ CREATE TABLE booknotes ( username text NOT NULL, work_id integer NOT NULL, edition_id integer NOT NULL default -1, notes text NOT NULL, primary key (username, work_id, edition_id) ); """ )
def teardown_class(cls): db = get_db() db.query("delete from bookshelves_books;") db.query("delete from booknotes;")
def setup_class(cls): web.config.db_parameters = dict(dbn="sqlite", db=":memory:") db = get_db() db.query(READING_LOG_DDL) db.query(BOOKNOTES_DDL)
def setup_class(cls): web.config.db_parameters = dict(dbn="sqlite", db=":memory:") db = get_db() db.query(RATINGS_DDL) db.query(OBSERVATIONS_DDL)