11# sqlite_rx [ ![ Downloads] ( https://pepy.tech/badge/sqlite-rx )] ( https://pepy.tech/project/sqlite-rx ) [ ![ Travis] ( https://travis-ci.org/aosingh/sqlite_rx.svg?branch=master )] ( https://travis-ci.org/aosingh/sqlite_rx ) [ ![ PyPI version] ( https://badge.fury.io/py/sqlite-rx.svg )] ( https://pypi.python.org/pypi/sqlite-rx ) [ ![ Coverage Status] ( https://coveralls.io/repos/github/aosingh/sqlite_rx/badge.svg?branch=master )] ( https://coveralls.io/github/aosingh/sqlite_rx?branch=master )
22[ ![ Python 3.6] ( https://img.shields.io/badge/python-3.6-blue.svg )] ( (https://www.python.org/downloads/release/python-370/) ) [ ![ Python 3.7] ( https://img.shields.io/badge/python-3.7-blue.svg )] ( https://www.python.org/downloads/release/python-370/ ) [ ![ Python 3.8] ( https://img.shields.io/badge/python-3.8-blue.svg )] ( https://www.python.org/downloads/release/python-380/ )
33[ ![ Python 3.9] ( https://img.shields.io/badge/python-3.9-blue.svg )] ( (https://www.python.org/downloads/release/python-390/) )
4- [ ![ PyPy3] ( https://img.shields.io/badge/python-PyPy3-blue.svg )] ( https://www.pypy.org/index.html )
4+ [ ![ PyPy3.6 ] ( https://img.shields.io/badge/python-PyPy3.6 -blue.svg )] ( https://www.pypy.org/index.html )
55## Background
66
77[ SQLite] ( https://www.sqlite.org/index.html ) is a lightweight database written in C.
@@ -21,8 +21,6 @@ Key Features
2121
2222# Install
2323
24- Currently, only Python 3 is supported.
25-
2624``` commandline
2725pip install sqlite_rx
2826```
@@ -31,9 +29,6 @@ pip install sqlite_rx
3129
3230## Server
3331
34- Following are the options to start an ` SQLiteServer `
35-
36- ### Python API
3732` SQLiteServer ` runs in a single thread and follows an event-driven concurrency model (using ` tornado's ` event loop) which minimizes the cost of concurrent client connections.
3833
3934``` python
@@ -59,14 +54,6 @@ if __name__ == '__main__':
5954 main()
6055```
6156
62- ### CLI to start a server
63-
64- Refer [ CLI] ( #cli )
65-
66- ### Docker
67-
68- Refer [ Docker Examples] ( #docker-examples )
69-
7057
7158## Client
7259
@@ -92,7 +79,8 @@ import logging.config
9279from sqlite_rx.client import SQLiteClient
9380from sqlite_rx import get_default_logger_settings
9481
95- # sqlite_rx comes with a default logger settings. You could use as below.
82+ # sqlite_rx comes with a default logger settings.
83+ # You could use as below.
9684logging.config.dictConfig(get_default_logger_settings(logging.DEBUG ))
9785
9886
@@ -102,56 +90,57 @@ client = SQLiteClient(connect_address="tcp://127.0.0.1:5000")
10290### CREATE TABLE statement
10391
10492``` python
105-
10693result = client.execute(" CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)" )
10794pprint(result)
10895```
10996OUTPUT
110- ``` text
111- {'error': None, 'items': []}
97+ ``` python
98+ {' error' : None ,
99+ ' items' : []}
112100```
113101
114102
115103### INSERT MANY rows
116104
117105``` python
118106purchases = [(' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
119- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
120- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
121- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
122- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
123- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
124- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
125- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
126- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
127- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
128- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
129- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
130- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
131- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
132- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
133- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
134- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
135- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
136- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
137- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
138- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
139- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
140- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
141- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
142- (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
143- (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
144- (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
145- ]
107+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
108+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
109+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
110+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
111+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
112+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
113+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
114+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
115+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
116+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
117+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
118+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
119+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
120+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
121+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
122+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
123+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
124+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
125+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
126+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
127+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
128+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
129+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 ),
130+ (' 2006-03-28' , ' BUY' , ' IBM' , 1000 , 45.00 ),
131+ (' 2006-04-05' , ' BUY' , ' MSFT' , 1000 , 72.00 ),
132+ (' 2006-04-06' , ' SELL' , ' XOM' , 500 , 53.00 )]
146133
147134result = client.execute(" INSERT INTO stocks VALUES (?,?,?,?,?)" , * purchases, execute_many = True )
148135pprint(result)
149136
150137```
151138OUTPUT
152139
153- ``` text
154- {'error': None, 'items': [], 'rowcount': 27}
140+ ``` python
141+ {' error' : None ,
142+ ' items' : [],
143+ ' rowcount' : 27 }
155144```
156145
157146### SELECT with WHERE clause
@@ -163,7 +152,7 @@ pprint(result)
163152```
164153OUTPUT
165154
166- ``` text
155+ ``` python
167156{' error' : None ,
168157 ' items' : [[' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
169158 [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
@@ -172,7 +161,10 @@ OUTPUT
172161 [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
173162 [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
174163 [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
175- ['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0]]}
164+ [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ],
165+ [' 2006-03-28' , ' BUY' , ' IBM' , 1000.0 , 45.0 ]],
166+ ' lastrowid' : 27 }
167+
176168```
177169
178170### Execute an SQL script
@@ -190,8 +182,11 @@ pprint(result)
190182```
191183
192184OUTPUT
193- ``` text
194- {'error': None, 'items': []}
185+
186+ ``` python
187+ {' error' : None ,
188+ ' items' : [],
189+ ' lastrowid' : 27 }
195190```
196191
197192Select the rows inserted using the above sql_script
@@ -202,9 +197,12 @@ pprint(result)
202197```
203198
204199OUTPUT
205- ``` text
206- {'error': None, 'items': [[2, 'Adam', '5547874'],
207- [3, 'Jack', '5484522']]}
200+ ``` python
201+ {' error' : None ,
202+ ' items' : [[1 , ' John' , ' 5557241' ],
203+ [2 , ' Adam' , ' 5547874' ],
204+ [3 , ' Jack' , ' 5484522' ]],
205+ ' lastrowid' : 3 }
208206```
209207
210208
@@ -219,7 +217,7 @@ pprint(result)
219217
220218OUTPUT
221219
222- ``` text
220+ ``` python
223221{' error' : {' message' : ' sqlite3.DatabaseError: not authorized' ,
224222 ' type' : ' sqlite3.DatabaseError' },
225223 ' items' : []}
@@ -228,13 +226,13 @@ OUTPUT
228226### SELECT statement; Table not present
229227``` python
230228from pprint import pprint
231- result = client.execute(" SELECT * FROM IDOLS " )
229+ result = client.execute(" SELECT * FROM STUDENTS " )
232230pprint(result)
233231
234232```
235233OUTPUT
236- ``` text
237- {'error': {'message': 'sqlite3.OperationalError: no such table: IDOLS ',
234+ ``` python
235+ {' error' : {' message' : ' sqlite3.OperationalError: no such table: STUDENTS ' ,
238236 ' type' : ' sqlite3.OperationalError' },
239237 ' items' : []}
240238```
0 commit comments