Skip to main content

convert json to relational db

Project description

Json2DB

Python3.6+

Just need defined a json object, then you can save it in to a relational DB like MySQL PostgreSQL or other DB.

Reason To Write This FrameWork

Although NoSQL Database like MongoDB is popular, we still need SQL DataBase for analyze data, so this module is helping us store json to database, and help us build them in db.

Feature

  • support mostly common database (MySQL, PostgreSQL, MSSQL, SQLite),

just set database like

JFactory(database='mysql')

See more in types

You can set str2col control Database Column Type like Text or VARCHAR and other.You can see more example in tests/test_comom_factory.py

  • Support Different Style of database column

If you want your db column like some_thing style

from json2db import JFactory, ColumnFormat
JFactory(column_fmt=ColumnFormat.UNDERLINE)

If you want your db column to be someThing style, use ColumnFormat.CAMEL

Default we do nothing as the json format.

  • Support Add a TimeStamp for your first table

  • Support set table args for your each table init

  • Support add comment to your field

Just Use {"field": {":my comment": "real value"}}, it can take the my comment to this field

  • Support Control the max_depth of your json table

PS: min is 0 which meaning it only one table for all json

  • Support Restore your data to anther table

if your data like d = {"father_id": 1, "father_name": "father", "brother": {"brother_name": "jack"}, 'sons': [{"son_name": "aa"}}, You can save it to a new table like father - son framework like {"father_id": 1, "brother_name": "jack", 'sons': [{"son_name": "aa", "father_name": "father"}]}

PS: you move brother field to father table, and move father field to son table,you can use

model.store(data=new_d, is_press=True)

See more sample please see tests

A Simple Example

For create_table ,store data and search data

from json2db import JFactory, ColumnFormat
d = {"aa": 1, "bb": 2, "brother": {"name": "jack", "namess": [{"other": "jack"}]}, 'sons': [{"son_name": "aa"}]}

factory = JFactory()
model = factory.from_json(data=d, root_name="data")
model.create_tables_in_db()
model.store(data=d)
model.search(search_args=[("aa", 1)], limit=2)

You can save your data to any sqlalchemy support database like MySQL, PostgreSQL,Oracle,SQLite(Default stored if you not set db_url) and so on. The db_url format please see more detail see https://docs.sqlalchemy.org/en/latest/core/engines.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json2db-3.2.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

json2db-3.2.2-py2.py3-none-any.whl (14.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file json2db-3.2.2.tar.gz.

File metadata

  • Download URL: json2db-3.2.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for json2db-3.2.2.tar.gz
Algorithm Hash digest
SHA256 188da108e820eaa5eae9e8597a4f2b3a0ae9a29698109bf42741c3bdfb3db94d
MD5 b2a61a4e7d591860644ed9ac773eaf8e
BLAKE2b-256 493e27b9b48a4694cdd5265986c7e76a0b94e096123099e94f9cd1b43cf87330

See more details on using hashes here.

File details

Details for the file json2db-3.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: json2db-3.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

File hashes

Hashes for json2db-3.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8aa25a68a58827d4b14dceb5b0329e65ab48fe613a8607f446604ee5aea01e1a
MD5 709c46f041246488f565732ecf701d1e
BLAKE2b-256 607e17ad46ef773b8fff8e03725390099304655608af4875f7b6abd69f78a840

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page