77![ Python 3.7, 3.8, 3.9, 3.10] ( https://img.shields.io/pypi/pyversions/simple-query-builder?color=blueviolet&style=flat-square )
88[ ![ GitHub license] ( https://img.shields.io/github/license/co0lc0der/simple-query-builder-python?style=flat-square )] ( https://github.com/co0lc0der/simple-query-builder-python/blob/main/LICENSE.md )
99
10- This is a small easy-to-use component 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 _ list_ by default. At present time the component supports SQLite (file or memory).
10+ 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 _ list_ by default. At present time the component supports SQLite (file or memory).
1111
1212## Contributing
1313
@@ -72,12 +72,10 @@ SELECT * FROM `users` WHERE `id` = 10;
7272```
7373- Select rows with two conditions
7474``` python
75- results = qb.select(' users' )\
76- .where([[' id' , ' >' , 1 ], ' and' , [' group_id' , ' =' , 2 ]])\
77- .all()
75+ results = qb.select(' users' ).where([[' id' , ' >' , 1 ], ' and' , [' group_id' , ' =' , 2 ]]).all()
7876```
7977``` sql
80- SELECT * FROM ` users` WHERE (` id` > 1 ) AND (` group_id` = 2 )
78+ SELECT * FROM ` users` WHERE (` id` > 1 ) AND (` group_id` = 2 );
8179```
8280- Select a row with a ` LIKE ` and ` NOT LIKE ` condition
8381``` python
@@ -86,15 +84,15 @@ results = qb.select('users').like(['name', '%John%']).all()
8684results = qb.select(' users' ).where([[' name' , ' LIKE' , ' %John%' ]]).all()
8785```
8886``` sql
89- SELECT * FROM ` users` WHERE (` name` LIKE ' %John%' )
87+ SELECT * FROM ` users` WHERE (` name` LIKE ' %John%' );
9088```
9189``` python
9290results = qb.select(' users' ).notLike([' name' , ' %John%' ]).all()
9391# or
9492results = qb.select(' users' ).where([[' name' , ' NOT LIKE' , ' %John%' ]]).all()
9593```
9694``` sql
97- SELECT * FROM ` users` WHERE (` name` NOT LIKE ' %John%' )
95+ SELECT * FROM ` users` WHERE (` name` NOT LIKE ' %John%' );
9896```
9997- Select rows with ` OFFSET ` and ` LIMIT `
10098``` python
@@ -150,7 +148,7 @@ groups = qb.select('orders', {'month_num': 'MONTH(`created_at`)', 'total': 'SUM(
150148``` sql
151149SELECT MONTH(` created_at` ) AS ` month_num` , SUM (` total` ) AS ` total`
152150FROM ` orders` WHERE (YEAR(` created_at` ) = 2020 )
153- GROUP BY ` month_num` HAVING (` total` > 20000 )
151+ GROUP BY ` month_num` HAVING (` total` > 20000 );
154152```
1551534 . ` JOIN ` . Supports ` INNER ` , ` LEFT OUTER ` , ` RIGHT OUTER ` , ` FULL OUTER ` and ` CROSS ` joins (` INNER ` is by default)
156154``` python
@@ -193,7 +191,7 @@ FROM `cabs_printers` AS `cp`
193191INNER JOIN ` cabs` AS ` cb` ON ` cp` .` cab_id` = ` cb` .` id`
194192INNER JOIN ` printer_models` AS ` p` ON ` cp` .` printer_id` = ` p` .` id`
195193INNER JOIN ` cartridge_types` AS ` c` ON p .cartridge_id = c .id
196- WHERE (` cp` .` cab_id` IN (11 ,12 ,13 )) OR (` cp` .` cab_id` = 5 ) AND (` p` .` id` > ` c` .` id` )
194+ WHERE (` cp` .` cab_id` IN (11 ,12 ,13 )) OR (` cp` .` cab_id` = 5 ) AND (` p` .` id` > ` c` .` id` );
197195```
198196- Insert a row
199197``` python
@@ -203,7 +201,7 @@ new_id = qb.insert('groups', {
203201}).go()
204202```
205203``` sql
206- INSERT INTO ` groups` (` name` , ` permissions` ) VALUES (' Moderator' , ' moderator' )
204+ INSERT INTO ` groups` (` name` , ` permissions` ) VALUES (' Moderator' , ' moderator' );
207205```
208206- Insert many rows
209207``` python
@@ -219,7 +217,7 @@ INSERT INTO `groups` (`name`, `role`)
219217VALUES (' Moderator' , ' moderator' ),
220218 (' Moderator2' , ' moderator' ),
221219 (' User' , ' user' ),
222- (' User2' , ' user' )
220+ (' User2' , ' user' );
223221```
224222- Update a row
225223``` python
@@ -243,7 +241,7 @@ qb.update('posts', {'status': 'published'})\
243241```
244242``` sql
245243UPDATE ` posts` SET ` status` = ' published'
246- WHERE (YEAR(` updated_at` ) > 2020 )
244+ WHERE (YEAR(` updated_at` ) > 2020 );
247245```
248246- Delete a row
249247``` python
0 commit comments