https://github.com/rapptz/asqlite
A simple async wrapper for sqlite3
https://github.com/rapptz/asqlite
Last synced: 25 days ago
JSON representation
A simple async wrapper for sqlite3
- Host: GitHub
- URL: https://github.com/rapptz/asqlite
- Owner: Rapptz
- License: mit
- Created: 2020-07-14T05:15:08.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-12T09:29:27.000Z (10 months ago)
- Last Synced: 2024-10-12T09:10:48.391Z (7 months ago)
- Language: Python
- Size: 25.4 KB
- Stars: 120
- Watchers: 6
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### asqlite
A simple and easy to use async wrapper for `sqlite3`.
This is basically the same as `sqlite3` except you use `async with` and `await` in front of most operations.
```python
import asyncio
import asqliteasync def main():
async with asqlite.connect('example.db') as conn:
async with conn.cursor() as cursor:
# Create table
await cursor.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')# Insert a row of data
await cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")# Save (commit) the changes
await conn.commit()asyncio.run(main())
```### Install
To install this via PyPI, use the `asqlite` package:
```
python3 -m pip install -U asqlite
```### Differences from `sqlite3`
This module differs from `sqlite3` in a few ways:
1. Connections are created with `journal_mode` set to `wal`.
2. Connections have foreign keys enabled by default.
3. [Implicit transactions are turned off][implicit-transactions]
4. The [`row_factory`][row_factory] is set to [`sqlite3.Row`][Row].
5. A `asqlite.Pool` is provided for connection pooling[implicit-transactions]: https://docs.python.org/3/library/sqlite3.html#transaction-control
[row_factory]: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.row_factory
[Row]: https://docs.python.org/3/library/sqlite3.html#sqlite3.Row### License
MIT