Skip to content

Commit 90d19d7

Browse files
committed
Merge branch 'dev' into main
# Conflicts: # docs/source/examples/index.rst
2 parents cc927fc + 60e10fc commit 90d19d7

22 files changed

+327
-540
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
Thanks for getting this release out! please stay tuned :)
1111

12+
## [0.2.0] - 2022-12-26
13+
14+
### Added
15+
16+
- Unit tests for getters.
17+
- `Database` read items from serialized JSON file.
18+
19+
### Changed
20+
21+
- Remove `Client`. use methods on `Database` instead of.
22+
1223
## [0.1.1] - 2022-12-26
1324

1425
### Added
@@ -36,6 +47,7 @@ Also this is not stable, so under alpha-test.
3647
- Set up files to being python package
3748
- Organized direcotries
3849

39-
[Unreleased]: https://github.com/joonas-yoon/json-as-db/compare/v0.1.1...HEAD
50+
[Unreleased]: https://github.com/joonas-yoon/json-as-db/compare/v0.2.0...HEAD
51+
[0.2.0]: https://github.com/joonas-yoon/json-as-db/compare/v0.1.1...v0.2.0
4052
[0.1.1]: https://github.com/joonas-yoon/json-as-db/compare/v0.1.0...v0.1.1
4153
[0.1.0]: https://github.com/joonas-yoon/json-as-db/releases/tag/v0.1.0

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
project = 'json-as-db'
2020
copyright = f'2022-{datetime.now().year}, Joonas Yoon'
2121
author = 'Joonas'
22-
release = '0.1.1'
22+
release = '0.2.0'
2323

2424
# -- General configuration ---------------------------------------------------
2525
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/source/examples/database/basic.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,35 @@ When ``commit()``, it saves its states and all items at that time. Using
139139
[{'type': 'Orange'}]
140140
141141
142+
Load
143+
^^^^
144+
145+
You can get the `Database` object from local JSON formatted file.
146+
147+
This method reads JSON file from directory where given path. In
148+
following example, it reads the file from ``path/dir/sample.json``.
149+
150+
.. code-block:: python
151+
152+
>>> db.load('path/dir/sample.json')
153+
{'data': {'2g4kaFAiDBPchz66HNPsZa': {'type': 'Orange'}}, 'creator': 'json_as_db', 'created_at': '2022-12-25T14:23:28.906103', 'version': '1.0.0', 'updated_at': '2022-12-25T14:23:28.906103'}
154+
155+
142156
Save
143157
^^^^
144158

145-
Save `Database` into file as JSON format. You can read from this saved file
146-
by getting methods with `Client` class.
159+
Save `Database` into file as JSON format. You can read from this saved file.
147160

148161
.. code-block:: python
149162
150-
>>> await db.save()
163+
>>> db.save()
151164
152165
It supports keyword parameters for JSON formatter and options to file saving.
153166
Please refer to the document page of modules in details.
154167

155168
.. code-block:: python
156169
157-
>>> await db.save(file_kwds={'encoding': 'utf-8'}, json_kwds={'indent': 4})
170+
>>> db.save(file_kwds={'encoding': 'utf-8'}, json_kwds={'indent': 4})
158171
159172
then you can see the file content as like the following,
160173

docs/source/examples/index.rst

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,6 @@ Examples
44
.. toctree::
55
:maxdepth: 2
66

7-
Client
8-
------
9-
10-
Constructor
11-
^^^^^^^^^^^
12-
13-
`Client` manages with root directory where contains JSON files for database.
14-
15-
When given ``root_dir`` as like ``Client(root_dir='path/dir')``, `Client` makes
16-
an empty directory with given path ``path/dir``.
17-
18-
.. code-block:: python
19-
20-
from json_as_db import Client
21-
22-
client = Client('path/dir')
23-
24-
25-
Create Database
26-
^^^^^^^^^^^^^^^
27-
28-
The name of database means the name of JSON file. so `Client` creates an empty
29-
file with JSON format: ``path/dir/sample.json``.
30-
31-
The ``create_database`` method returns an instance of `Database` type, and you
32-
can deal with this object just like dictionary.
33-
34-
.. code-block:: python
35-
36-
>>> await client.create_database('sample')
37-
{'data': {}, 'creator': 'json_as_db', 'created_at': '2022-12-25T14:23:28.906103', 'version': '1.0.0', 'updated_at': '2022-12-25T14:23:28.906103'}
38-
39-
40-
Get Database from file
41-
^^^^^^^^^^^^^^^^^^^^^^
42-
43-
After create database with the below creating method, using file name as its
44-
database name, you can get it from local JSON formatted file as `Database`
45-
object.
46-
47-
This method reads and opens JSON file from directory where `Client` knows. In
48-
following example, `Client` read the file from ``path/dir/sample.json``.
49-
50-
.. code-block:: python
51-
52-
>>> await client.get_database('sample')
53-
{'data': {}, 'creator': 'json_as_db', 'created_at': '2022-12-25T14:23:28.906103', 'version': '1.0.0', 'updated_at': '2022-12-25T14:23:28.906103'}
54-
55-
56-
Remove Database
57-
^^^^^^^^^^^^^^^
58-
59-
.. warning::
60-
Please be aware of that file can not be recovered after running.
61-
62-
To remove local JSON file using `Client`, you can run this ``remove_database``
63-
method.
64-
65-
.. code-block:: python
66-
67-
client.remove_database('sample')
68-
697

708
Database
719
--------
@@ -75,7 +13,28 @@ except only for some of setters.
7513

7614
.. _dictionary: https://docs.python.org/3/library/stdtypes.htmldict
7715

78-
So you can use them as dictionary-like. please see the following examples.
16+
So you can use them as dictionary-like, including useful CRUD methods and more.
17+
18+
.. code-block:: python
19+
20+
>>> from json_as_db import Database
21+
>>> db = Database()
22+
>>> db.add([
23+
... { "id": 1001, "type": "Regular" },
24+
... { "id": 1002, "type": "Chocolate" }
25+
... ])
26+
["aT7kM2pW8L7JisSkNjpAhr", "RUJGcVBFANvNRReXa8U3En"]
27+
>>> db.get("aT7kM2pW8L7JisSkNjpAhr")
28+
{"id": 1001, "type": "Regular"}
29+
>>> db.count()
30+
2
31+
>>> db.all()
32+
[{"id": 1001, "type": "Regular"}, {"id": 1002, "type": "Chocolate"}]
33+
>>> db.save('path/dir/file.json')
34+
35+
36+
Moreover, `Database` provides and supports many operations.
37+
Please see the following examples.
7938

8039
.. toctree::
8140
:maxdepth: 2

docs/source/modules/client.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/source/modules/database.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/source/modules/index.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Modules
22
=======
33

4-
.. toctree::
5-
:maxdepth: 2
4+
Database
5+
--------
66

7-
client
8-
database
7+
.. automodule:: json_as_db.Database
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "json_as_db"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
description = "Using JSON as very lightweight database"
55
readme = "README.md"
66
license = "MIT"

src/json_as_db/Client/BaseClient.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/json_as_db/Client/Client.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)