Skip to main content

QueryBuilder python module

Latest Version GitHub repo size GitHub license Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 PyPI PyPI - Downloads

This is a small easy-to-use module for working with a database. It provides some public methods to compose SQL queries and manipulate data. Each SQL query is prepared and safe. QueryBuilder fetches data to dictionary by default. At present time the component supports SQLite (file or memory).

Contributing

Bug reports and/or pull requests are welcome

License

The module is available as open source under the terms of the MIT license

Installation

Install the current version with PyPI:

pip install simple-query-builder

Or from Github:

pip install https://github.com/co0lc0der/simple-query-builder-python/archive/main.zip

How to use

Import the module and init QueryBuilder with Database()

from simple_query_builder import *

qb = QueryBuilder(DataBase(), 'my_db.db')

# or DB in memory
qb = QueryBuilder(DataBase(), ':memory:')

Usage examples

Select all rows from a table

results = qb.select('users').all()

Result query

SELECT * FROM `users`;

Select rows with two conditions

results = qb.select('users').where([['id', '>', 1], 'and', ['group_id', '=', 2]]).all()

Result query

SELECT * FROM `users` WHERE (`id` > 1) AND (`group_id` = 2);

Update a row

qb.update('users', {
        'username': 'John Doe',
        'status': 'new status'
    })\
    .where([['id', '=', 7]])\
    .limit()\
    .go()

Result query

UPDATE `users` SET `username` = 'John Doe', `status` = 'new status'
WHERE `id` = 7 LIMIT 1;

More examples you can find in documentation

ToDo

I'm going to add the next features into future versions

  • write more unit testes
  • add subqueries for QueryBuilder
  • add BETWEEN
  • add WHERE EXISTS
  • add TableBuilder class (for beginning CREATE TABLE, move qb.drop() and qb.truncate() into it)
  • add MySQL support
  • add PostgreSQL support
  • add WITH
  • and probably something more

Metadata

Release files for simple-query-builder 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simple-query-builder 0.4
File Size Uploaded
simple_query_builder-0.4.tar.gz 12.8 kB Details

Release files / simple_query_builder-0.4.tar.gz

Download URL simple_query_builder-0.4.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d81314a555d3ee2ff51c978f4a1a5650e4343e1253183ed1b32723dda79747d7
BLAKE2b-256 checksum
How to use checksums
7440749999ea30c08ff1c06ccf9886812056ffa3a4b5c957a5bbb0dab54143e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.4 This release

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page