GithubHelp home page GithubHelp logo

ownport / sqlite2json Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 4 KB

Simple script for returning SQL query result as JSONline

License: MIT License

Makefile 36.44% Python 63.56%
sqlite3 python3 jsonlines

sqlite2json's Introduction

sqlite2json

Simple script for returning SQL query result as JSONline

How to use

./sqlite2json --help
usage: sqlite2json [-h] --database DATABASE --sql SQL
                   [--fetch-size FETCH_SIZE] [--udf UDF]

optional arguments:
  -h, --help            show this help message and exit
  --database DATABASE   the path to sqlite3 database
  --sql SQL             SQL query
  --fetch-size FETCH_SIZE
                        Fetch size, default: 1000 records
  --udf UDF             Custom UDF functions, the format fieldname:udf

Examples

simple query

.sqlite2json --database metrics.sqlite3 --sql "SELECT * FROM sqlite_master;"
{"type": "table", "tbl_name": "definitions", "rootpage": 2, "name": "definitions", "sql": "CREATE TABLE definitions (v)"}
{"type": "table", "tbl_name": "metrics", "rootpage": 3, "name": "metrics", "sql": "CREATE TABLE metrics (metric_id, value)"}

query with udf

./sqlite2json --database metrics.sqlite3 \
    --sql "SELECT metric_id, group_concat(value) AS values FROM (SELECT metric_id, value FROM metrics LIMIT 10) GROUP BY metric_id;" \
    --udf "values:'{}'.split(',')"
    
{"metric_id": 100, "values": ["10", "14", "51", "62", "37", "18", "91"]}
{"metric_id": 815, "values": ["12", "34", "25", "65", "71", "86", "95"]}

sqlite2json's People

Contributors

ownport avatar

Watchers

 avatar  avatar

sqlite2json's Issues

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.