-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from arekit.contrib.utils.data.readers.base import BaseReader | ||
from arekit.contrib.utils.data.storages.sqlite_based import SQliteBasedRowsStorage | ||
|
||
|
||
class SQliteReader(BaseReader): | ||
|
||
def __init__(self, table_name): | ||
self.__table_name = table_name | ||
|
||
def extension(self): | ||
return ".sqlite" | ||
|
||
def read(self, target): | ||
return SQliteBasedRowsStorage(path=target, table_name=self.__table_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sqlite3 | ||
from arekit.common.data.storages.base import BaseRowsStorage | ||
|
||
|
||
class SQliteBasedRowsStorage(BaseRowsStorage): | ||
|
||
def __init__(self, path, table_name): | ||
self.__path = path | ||
self.__table_name = table_name | ||
self.__conn = None | ||
|
||
def _iter_rows(self): | ||
with sqlite3.connect(self.__path) as conn: | ||
cursor = conn.execute(f"select * from {self.__table_name}") | ||
for row_index, row in enumerate(cursor.fetchall()): | ||
row_dict = {cursor.description[i][0]: value for i, value in enumerate(row)} | ||
yield row_index, row_dict |