Giter VIP home page Giter VIP logo

sqlite-viewer's Introduction

sqlite viewer

A little python script for running a query against a sqlite database and printing the results.

Created because I got tired of this mess:

sqlite3

and this mess:

litecli

here's what it looks like:

sqlite-viewer

It wraps the text in the column with the longest values, so all of the columns stay vertically aligned in the output.

setup

The .py script has a hashbang, so you can symlink it to somewhere on your path, like this:

$ ln -s ./sqlite-viewer.py ~/.local/bin/sql
$ chmod +x ~/.local/bin/sql

then you can run it like so:

$ sql example.db "select * from data"

usage

Simple usage to run a query against a database:

sql database command

This will return up to 25 rows. If you need to see more, use LIMIT with an OFFSET.

I've included the example database from the above screenshots, for testing/playing around purposes.

counting

I find myself writing queries to count the number of values in a set of columns a lot, so I've included a parameter that can build these queries automatically:

sql database -count table:columns

For example, I have a database containing all of my nginx access logs. If I want to see which URLs are most frequently accessed and by which HTTP method, I can do this:

$ sql logs.db -count logs:request,method
request                      method  count  
/                            GET     14660  
/robots.txt                  GET     5503
...

which will expand to this query:

SELECT request, method count(1) AS count
FROM logs
GROUP BY request, method
ORDER BY count(1) DESC

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.