Skip to content

Commit ecf594c

Browse files
committed
Feature Added: Show & Export Database
1 parent b645c89 commit ecf594c

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

filexdb/database.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, Type, List
22

33
from .collection import Collection
4-
from .fileio import BinaryFileIO, JsonFileIO
4+
from .fileio import BinaryFileIO, JsonFileIO, Export
55
from .document import JsonArray, Document
66

77

@@ -19,7 +19,7 @@ def __init__(self, db_name: str, data_dir=None, mode="binary"):
1919
:param db_name: Name of Database without file extension.
2020
:param data_dir: Where the Database will be stored.
2121
"""
22-
self._database = Document({})
22+
self._database = {}
2323
self._db_name = db_name
2424
self._data_dir = data_dir
2525

@@ -55,3 +55,21 @@ def show_collections(self) -> JsonArray:
5555

5656
return _result
5757

58+
def show(self) -> Document:
59+
"""
60+
61+
:return: Database
62+
"""
63+
self._database = self._file_handler.read()
64+
return Document(self._database, False)
65+
66+
def export(self, _file_name, _file_dir=None, _mode="json"):
67+
"""
68+
69+
:param _file_name:
70+
:param _file_dir:
71+
:param _mode:
72+
:return:
73+
"""
74+
75+
e = Export(self.show(), _file_name, _file_dir, _mode)

filexdb/document.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import json
44
from .fileio import Export
55

6+
__all__ = ("Document", "JsonArray")
67

78
def _get_id():
89
_id = uuid.uuid1()
910
return _id.hex
1011

1112

1213
class Document(dict):
13-
def __init__(self, value: Mapping) -> None:
14+
def __init__(self, value: Mapping, gen_id: bool = True) -> None:
1415
self.id = None
1516

1617
_id_obj = {
@@ -20,6 +21,8 @@ def __init__(self, value: Mapping) -> None:
2021
if "_id_" in value.keys():
2122
self._doc = value
2223
self.id = value["_id_"]
24+
elif "_id_" not in value.keys() and not gen_id:
25+
self._doc = value
2326
else:
2427
self._doc = _id_obj
2528
for k, v in value.items():

filexdb/fileio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import io
55
from abc import ABC, abstractmethod
66

7-
__all__ = ("FileIO", "JsonFileIO", "BinaryFileIO")
7+
__all__ = ("FileIO", "JsonFileIO", "BinaryFileIO", "Export")
88

99
from typing import Tuple
1010

0 commit comments

Comments
 (0)