Beispiel #1
0
    def add_list(self, name, path, colour):
        """
        Inserts a new list into the cache.

        Returns the id of the newly inserted list.
        """

        result = self._conn.execute(
            'SELECT name FROM lists WHERE path = ?',
            (path, ),
        ).fetchone()

        if result:
            return result['name']

        try:
            self._conn.execute(
                "INSERT INTO lists (name, path, colour) VALUES (?, ?, ?)",
                (
                    name,
                    path,
                    colour,
                ),
            )
        except sqlite3.IntegrityError as e:
            raise exceptions.AlreadyExists('list', name) from e

        return self.add_list(name, path, colour)
Beispiel #2
0
 def add_file(self, list_name, path, mtime):
     try:
         self._conn.execute(
             '''
             INSERT INTO files (
                 list_name,
                 path,
                 mtime
             ) VALUES (?, ?, ?);
             ''', (
                 list_name,
                 path,
                 mtime,
             ))
     except sqlite3.IntegrityError as e:
         raise exceptions.AlreadyExists('file', list_name) from e