Git Product home page Git Product logo

json2db's Introduction

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

json2db's People

Contributors

mrzhangboss avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.