Skip to content

Commit 322c3c0

Browse files
author
Abhishek Singh
committed
v1.0.0 changes
1. Test case adapted for PyPy platform 2. Added PyPy3.7 and PyPy3.6 in the build pipeline
1 parent cc60ec6 commit 322c3c0

3 files changed

Lines changed: 79 additions & 62 deletions

File tree

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ matrix:
1111
python: 3.9
1212
- os: linux
1313
python: pypy3.6-7.1.1
14+
- os: linux
15+
python: pypy3.6-7.2.0
16+
- os: linux
17+
python: pypy3.6-7.3.3
18+
- os: linux
19+
python: pypy3.7-7.3.3
1420
install:
1521
- pip install --upgrade pip
1622
- pip install pytest coverage coveralls

README.md

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
2725
pip 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
9279
from sqlite_rx.client import SQLiteClient
9380
from 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.
9684
logging.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-
10693
result = client.execute("CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)")
10794
pprint(result)
10895
```
10996
OUTPUT
110-
```text
111-
{'error': None, 'items': []}
97+
```python
98+
{'error': None,
99+
'items': []}
112100
```
113101

114102

115103
### INSERT MANY rows
116104

117105
```python
118106
purchases = [('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

147134
result = client.execute("INSERT INTO stocks VALUES (?,?,?,?,?)", *purchases, execute_many=True)
148135
pprint(result)
149136

150137
```
151138
OUTPUT
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
```
164153
OUTPUT
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

192184
OUTPUT
193-
```text
194-
{'error': None, 'items': []}
185+
186+
```python
187+
{'error': None,
188+
'items': [],
189+
'lastrowid': 27}
195190
```
196191

197192
Select the rows inserted using the above sql_script
@@ -202,9 +197,12 @@ pprint(result)
202197
```
203198

204199
OUTPUT
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

220218
OUTPUT
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
230228
from pprint import pprint
231-
result = client.execute("SELECT * FROM IDOLS")
229+
result = client.execute("SELECT * FROM STUDENTS")
232230
pprint(result)
233231

234232
```
235233
OUTPUT
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
```

sqlite_rx/tests/plain/test_queries.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import platform
2+
3+
PYPY = True if platform.python_implementation() == "PyPy" else False
4+
5+
16

27
def test_table_creation(plain_client):
38
result = plain_client.execute('CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)')
@@ -75,14 +80,18 @@ def test_select_before_update(plain_client):
7580
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
7681
]
7782
result = plain_client.execute('SELECT * FROM stocks')
78-
expected_result = {'error': None, 'items': [list(purchase) for purchase in purchases], 'lastrowid': 27}
83+
expected_result = {'error': None, 'items': [list(purchase) for purchase in purchases]}
84+
if not PYPY:
85+
expected_result['lastrowid'] = 27
7986
assert result == expected_result
8087

8188

8289
def test_update(plain_client):
8390
args = ('IBM',)
8491
result = plain_client.execute('UPDATE stocks SET price = 480 where symbol = ?', *args)
85-
expected_result = {'error': None, 'items': [], 'lastrowid': 27, 'rowcount': 9}
92+
expected_result = {'error': None, 'items': [], 'rowcount': 9}
93+
if not PYPY:
94+
expected_result['lastrowid'] = 27
8695
assert result == expected_result
8796

8897

@@ -117,7 +126,9 @@ def test_select(plain_client):
117126
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
118127
]
119128
result = plain_client.execute('SELECT * FROM stocks')
120-
expected_result = {'error': None, 'items': [list(purchase) for purchase in purchases], 'lastrowid': 27}
129+
expected_result = {'error': None, 'items': [list(purchase) for purchase in purchases]}
130+
if not PYPY:
131+
expected_result['lastrowid'] = 27
121132
assert result == expected_result
122133

123134

@@ -127,7 +138,9 @@ def test_sql_script(plain_client):
127138
128139
INSERT INTO users(name, phone) VALUES ('John', '5557241'),
129140
('Adam', '5547874'), ('Jack', '5484522');'''
130-
expected_result = {"error": None, 'items': [], 'lastrowid': 27}
141+
expected_result = {"error": None, 'items': []}
142+
if not PYPY:
143+
expected_result['lastrowid'] = 27
131144
result = plain_client.execute(script, execute_script=True)
132145
assert expected_result == result
133146

0 commit comments

Comments
 (0)