Skip to main content

generates SQL query from natural language for your PostrgreSQL database

Project description

NLSQL

Generates SQL query from natural language for your PostrgreSQL database. Simply connects to your database, gets the schema and generates query appropriately.

User Guide

you can use nlsql as httpserver and as a cli-command

Installation

pip install nlsql

run as http server

  1. start up the api server
    nlsql -s
    
  2. get results via curl
    curl --location 'http://localhost:8000/query' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "question": "get users with post that has top views and top reactions in the last 24 hours",
    "db_url": "postgresql://postgres:postgres@localhost:5432/postgres"
    }'
    

run as cli command

nlsql -m "./Nous-Hermes-2-Mistral-7B-DPO.Q4_0.gguf" -d "postgresql://postgres:postgres@localhost:5432/postgres" -q "get users with post that has top views and top reactions in the last 24 hours"

Response

    SELECT DISTINCT ON (users.id) users.id, users.name
    FROM users
    JOIN posts ON users.id = posts.post_creator_user_id
    WHERE posts.created_at > now() - interval '1 day'
    GROUP BY users.id, users.name
    HAVING SUM(posts.views) >= ALL (SELECT SUM(views) FROM posts WHERE created_at > now() - interval '1 day') AND SUM(posts.reactions) >= ALL (SELECT SUM(reactions) FROM posts WHERE created_at > now() - interval '1 day');

response was generated over the following users and posts tables:

postgres=# \d users
   Column   |            Type             | Collation | Nullable |              Default              
------------+-----------------------------+-----------+----------+-----------------------------------
 id         | integer                     |           | not null | nextval('users_id_seq'::regclass)
 name       | text                        |           |          | 
 created_at | timestamp without time zone |           |          | 

postgres=# \d posts
        Column        |            Type             | Collation | Nullable |              Default              
----------------------+-----------------------------+-----------+----------+-----------------------------------
 id                   | integer                     |           | not null | nextval('posts_id_seq'::regclass)
 title                | text                        |           |          | 
 url                  | text                        |           |          | 
 post_creator_user_id | integer                     |           |          | 
 views                | integer                     |           |          | 
 reactions            | integer                     |           |          | 
 created_at           | timestamp without time zone |           |          | 
 updated_at           | timestamp without time zone |           |          | 

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

nlsql-0.0.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nlsql-0.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file nlsql-0.0.2.tar.gz.

File metadata

  • Download URL: nlsql-0.0.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for nlsql-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2e8abc01f3e2e5157dac831d60cafffbcd90321a723b110483cfd160bc60f2fc
MD5 d2b87efd82841ec5191c3b3247050251
BLAKE2b-256 862d950ca49b54ac27b868f90969091884533ff478b90fca91f1e32aeb55205c

See more details on using hashes here.

File details

Details for the file nlsql-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: nlsql-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for nlsql-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d098ab3a40e6d1e5d2f61e49b60751d0400dd843ed0fa760ff61b3e2ff92db9c
MD5 f1189e0a57e4c4808cbfbd45401748f3
BLAKE2b-256 6cc37e094dbab2e3eccd48e5da0212a7ec5a1b5a9f2730b1dfe5ee2a34c3e7e1

See more details on using hashes here.

Supported by

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