@@ -32,15 +32,15 @@ pip install https://github.com/co0lc0der/simple-query-builder-python/archive/mai
32
32
## How to use
33
33
### Main public methods
34
34
- ` get_sql() ` returns SQL query string which will be executed
35
- - ` get_params() ` returns an array of parameters for a query
35
+ - ` get_params() ` returns a tuple of parameters for a query
36
36
- ` get_result() ` returns query's result
37
37
- ` get_count() ` returns result's rows count
38
38
- ` get_error() ` returns ` True ` if an error is had
39
39
- ` get_error_message() ` returns an error message if an error is had
40
40
- ` set_error(message) ` sets ` _error ` to ` True ` and ` _error_essage `
41
41
- ` get_first() ` returns the first item of results
42
42
- ` get_last() ` returns the last item of results
43
- - ` reset() ` resets state to default values (except PDO property)
43
+ - ` reset() ` resets state to default values
44
44
- ` all() ` executes SQL query and returns all rows of result (` fetchall() ` )
45
45
- ` one() ` executes SQL query and returns the first row of result (` fetchone() ` )
46
46
- ` column(col_index) ` executes SQL query and returns the needed column of result, ` col_index ` is ` 0 ` by default
@@ -55,7 +55,14 @@ pip install https://github.com/co0lc0der/simple-query-builder-python/archive/mai
55
55
``` python
56
56
from simple_query_builder import *
57
57
58
- qb = QueryBuilder(DataBase(), ' my_db.db' )
58
+ # if you want to get results as a list of dictionaries (by default since 0.3.5)
59
+ qb = QueryBuilder(DataBase(), ' my_db.db' ) # result_dict=True, print_errors=False
60
+
61
+ # or if you want to get results as a list of tuples (since 0.3.5)
62
+ qb = QueryBuilder(DataBase(), ' my_db.db' , result_dict = False )
63
+
64
+ # for printing errors into terminal (since 0.3.5)
65
+ qb = QueryBuilder(DataBase(), ' my_db.db' , print_errors = True )
59
66
```
60
67
### Usage examples
61
68
- Select all rows from a table
@@ -86,20 +93,20 @@ SELECT * FROM `users` WHERE (`id` > 1) AND (`group_id` = 2);
86
93
- Select a row with a ` LIKE ` and ` NOT LIKE ` condition
87
94
``` python
88
95
results = qb.select(' users' ).like([' name' , ' %John%' ]).all()
89
- # or since 0.3.5
90
- results = qb.select(' users' ).like(' name' , ' %John%' ).all()
91
96
# or
92
97
results = qb.select(' users' ).where([[' name' , ' LIKE' , ' %John%' ]]).all()
98
+ # or since 0.3.5
99
+ results = qb.select(' users' ).like(' name' , ' %John%' ).all()
93
100
```
94
101
``` sql
95
102
SELECT * FROM ` users` WHERE (` name` LIKE ' %John%' );
96
103
```
97
104
``` python
98
105
results = qb.select(' users' ).not_like([' name' , ' %John%' ]).all()
99
- # or since 0.3.5
100
- results = qb.select(' users' ).not_like(' name' , ' %John%' ).all()
101
106
# or
102
107
results = qb.select(' users' ).where([[' name' , ' NOT LIKE' , ' %John%' ]]).all()
108
+ # or since 0.3.5
109
+ results = qb.select(' users' ).not_like(' name' , ' %John%' ).all()
103
110
```
104
111
``` sql
105
112
SELECT * FROM ` users` WHERE (` name` NOT LIKE ' %John%' );
0 commit comments