Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View data by method #13

Open
joonas-yoon opened this issue Jan 30, 2023 · 0 comments
Open

View data by method #13

joonas-yoon opened this issue Jan 30, 2023 · 0 comments

Comments

@joonas-yoon
Copy link
Owner

joonas-yoon commented Jan 30, 2023

Looking like as following:

>>> from json_as_db.formatter import TableFormatter, TreeFormatter
>>> db.view(TableFormatter())
age  grouped  ...  job                name
32   True     ...  Camera operator    Layne
17   False    ...  Flying instructor  Somerled
9    True     ...  Inventor           Joon-Ho
...  ...      ...  ...                ...
23   None     ...  Publican           Melanie
54   True     ...  Racing driver      Eike
41   None     ...  Barrister          Tanja


[100 items, 9 keys]

>>> db.view(TreeFormatter(key='short', indent=2)) # key: literal['full', 'short']
'2xtoAg':
|- age: 32
|- grouped: True
|- ...
|- job: Camera operator
|- name: Layne
'D8A2Wy':
|- age: 17
|- grouped: False
|- ...
|- job: Flying instructor
|- name: Somerled
...

consistent setting up when initialize

>>> from json_as_db import Database
>>> from json_as_db.formatter import TableFormatter, TreeFormatter

>>> formatter = TreeFormatter(...)
>>> db = Database(formatter=formatter)
>>> db = Database.load('path/file.json', formatter=formatter) # also this should be supported
>>> db.view() # Now it is optional

so anybody can extend and use their own formmating to represent database.

>>> from json_as_db.formatter import Formatter
>>> class MyFormatter(Formatter):
>>>     pass
>>> ...
@joonas-yoon joonas-yoon converted this from a draft issue Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant