fix some mypy lint
This commit is contained in:
parent
9d7d80d3a5
commit
7c7a1fcde2
6 changed files with 20 additions and 6 deletions
|
|
@ -15,6 +15,7 @@ class Store:
|
|||
self.dbpath = path
|
||||
if self.connection is not None:
|
||||
return self.connection
|
||||
assert self.dbpath is not None
|
||||
self.connection = sqlite3.connect(
|
||||
self.dbpath, isolation_level=None
|
||||
) # auto commit
|
||||
|
|
@ -45,6 +46,7 @@ class Store:
|
|||
)
|
||||
|
||||
def add(self, posts: Iterable[Post]):
|
||||
assert self.connection is not None
|
||||
sql = f"""
|
||||
insert into post(content, source, date)
|
||||
values (?, ?, ?)
|
||||
|
|
@ -59,6 +61,7 @@ class Store:
|
|||
)
|
||||
|
||||
def _select(self, condition="", params=[]) -> Iterable[Post]:
|
||||
assert self.connection is not None
|
||||
sql = f"select id, content, date, source from post {condition}"
|
||||
for row in self.connection.execute(sql, params):
|
||||
id, content, date, source = row
|
||||
|
|
@ -71,6 +74,7 @@ class Store:
|
|||
cond = "where id in (select id from post order by random() limit 1)"
|
||||
for post in self._select(cond):
|
||||
return post
|
||||
return None
|
||||
|
||||
def search(self, term, skip: int = 0) -> Iterable[Post]:
|
||||
cond = "where content like ? order by date desc limit -1 offset ?"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue