Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple SQL Query Builder Python module

License

NotificationsYou must be signed in to change notification settings

co0lc0der/simple-query-builder-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest VersionGitHub repo sizeGitHub licensePython 3.7, 3.8, 3.9, 3.10, 3.11, 3.12PyPIPyPI - 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 todictionary 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 theMIT license

Installation

Install the current version withPyPI:

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 initQueryBuilder withDatabase()

fromsimple_query_builderimport*qb=QueryBuilder(DataBase(),'my_db.db')# or DB in memoryqb=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`=7LIMIT1;

More examples you can find indocumentation

ToDo

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

  • write more unit testes
  • add subqueries for QueryBuilder
  • addBETWEEN
  • addWHERE EXISTS
  • add TableBuilder class (for beginningCREATE TABLE, moveqb.drop() andqb.truncate() into it)
  • add MySQL support
  • add PostgreSQL support
  • addWITH
  • and probably something more

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp