Skip to content

Commit

Permalink
v1.0.0 changes
Browse files Browse the repository at this point in the history
1. Test case adapted for PyPy platform
2. Added PyPy3.7 and PyPy3.6 in the build pipeline
  • Loading branch information
Abhishek Singh committed Dec 31, 2020
1 parent cc60ec6 commit 322c3c0
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -11,6 +11,12 @@ matrix:
python: 3.9
- os: linux
python: pypy3.6-7.1.1
- os: linux
python: pypy3.6-7.2.0
- os: linux
python: pypy3.6-7.3.3
- os: linux
python: pypy3.7-7.3.3
install:
- pip install --upgrade pip
- pip install pytest coverage coveralls
Expand Down
114 changes: 56 additions & 58 deletions README.md
@@ -1,7 +1,7 @@
# 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)
[![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/)
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)]((https://www.python.org/downloads/release/python-390/))
[![PyPy3](https://img.shields.io/badge/python-PyPy3-blue.svg)](https://www.pypy.org/index.html)
[![PyPy3.6](https://img.shields.io/badge/python-PyPy3.6-blue.svg)](https://www.pypy.org/index.html)
## Background

[SQLite](https://www.sqlite.org/index.html) is a lightweight database written in C.
Expand All @@ -21,8 +21,6 @@ Key Features

# Install

Currently, only Python 3 is supported.

```commandline
pip install sqlite_rx
```
Expand All @@ -31,9 +29,6 @@ pip install sqlite_rx

## Server

Following are the options to start an `SQLiteServer`

### Python API
`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.

```python
Expand All @@ -59,14 +54,6 @@ if __name__ == '__main__':
main()
```

### CLI to start a server

Refer [CLI](#cli)

### Docker

Refer [Docker Examples](#docker-examples)


## Client

Expand All @@ -92,7 +79,8 @@ import logging.config
from sqlite_rx.client import SQLiteClient
from sqlite_rx import get_default_logger_settings

# sqlite_rx comes with a default logger settings. You could use as below.
# sqlite_rx comes with a default logger settings.
# You could use as below.
logging.config.dictConfig(get_default_logger_settings(logging.DEBUG))


Expand All @@ -102,56 +90,57 @@ client = SQLiteClient(connect_address="tcp://127.0.0.1:5000")
### CREATE TABLE statement

```python

result = client.execute("CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)")
pprint(result)
```
OUTPUT
```text
{'error': None, 'items': []}
```python
{'error': None,
'items': []}
```


### INSERT MANY rows

```python
purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
]
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00),
('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
('2006-04-06', 'SELL', 'XOM', 500, 53.00)]

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

```
OUTPUT

```text
{'error': None, 'items': [], 'rowcount': 27}
```python
{'error': None,
'items': [],
'rowcount': 27}
```

### SELECT with WHERE clause
Expand All @@ -163,7 +152,7 @@ pprint(result)
```
OUTPUT

```text
```python
{'error': None,
'items': [['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
Expand All @@ -172,7 +161,10 @@ OUTPUT
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0]]}
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0],
['2006-03-28', 'BUY', 'IBM', 1000.0, 45.0]],
'lastrowid': 27}

```

### Execute an SQL script
Expand All @@ -190,8 +182,11 @@ pprint(result)
```

OUTPUT
```text
{'error': None, 'items': []}

```python
{'error': None,
'items': [],
'lastrowid': 27}
```

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

OUTPUT
```text
{'error': None, 'items': [[2, 'Adam', '5547874'],
[3, 'Jack', '5484522']]}
```python
{'error': None,
'items': [[1, 'John', '5557241'],
[2, 'Adam', '5547874'],
[3, 'Jack', '5484522']],
'lastrowid': 3}
```


Expand All @@ -219,7 +217,7 @@ pprint(result)

OUTPUT

```text
```python
{'error': {'message': 'sqlite3.DatabaseError: not authorized',
'type': 'sqlite3.DatabaseError'},
'items': []}
Expand All @@ -228,13 +226,13 @@ OUTPUT
### SELECT statement; Table not present
```python
from pprint import pprint
result = client.execute("SELECT * FROM IDOLS")
result = client.execute("SELECT * FROM STUDENTS")
pprint(result)

```
OUTPUT
```text
{'error': {'message': 'sqlite3.OperationalError: no such table: IDOLS',
```python
{'error': {'message': 'sqlite3.OperationalError: no such table: STUDENTS',
'type': 'sqlite3.OperationalError'},
'items': []}
```
Expand Down
21 changes: 17 additions & 4 deletions sqlite_rx/tests/plain/test_queries.py
@@ -1,3 +1,8 @@
import platform

PYPY = True if platform.python_implementation() == "PyPy" else False



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


def test_update(plain_client):
args = ('IBM',)
result = plain_client.execute('UPDATE stocks SET price = 480 where symbol = ?', *args)
expected_result = {'error': None, 'items': [], 'lastrowid': 27, 'rowcount': 9}
expected_result = {'error': None, 'items': [], 'rowcount': 9}
if not PYPY:
expected_result['lastrowid'] = 27
assert result == expected_result


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


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

0 comments on commit 322c3c0

Please sign in to comment.