Skip to content

Commit

Permalink
#538 addded
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolay-r committed Dec 18, 2023
1 parent ad4312c commit e912af4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions arekit/contrib/utils/data/readers/sqlite.py
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)
17 changes: 17 additions & 0 deletions arekit/contrib/utils/data/storages/sqlite_based.py
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

0 comments on commit e912af4

Please sign in to comment.