sqlite3i
An opinionated sqlite3 wrapper.
The main goal of this package is simply to have stmt.execute() return bool instead of a cursor object.
So that it can be useful to indicate True if the query succeeds, or False otherwise.
Empty results on INSERT, UPDATE, DELETE, and SELECT are considered as False.
It adopts the prepare - execute pattern merely for the user experience.
Synchronous usage
from sqlite3i import Database
db = Database('example.db')
def main():
try:
db.connect(timeout=30)
stmt = db.prepare(
'CREATE TABLE IF NOT EXISTS users ('
' id INTEGER PRIMARY KEY,'
' name TEXT NOT NULL,'
' age INTEGER NOT NULL'
');'
)
stmt.execute() # True
stmt = db.prepare('SELECT * FROM users')
stmt.execute() # False, no rows yet!
stmt = db.prepare('SELECT * FROM user')
stmt.execute() # False, no such table!
stmt = db.prepare(
'INSERT INTO users (name, age) VALUES (?, ?)'
)
stmt.execute(['Alice']) # False
stmt.execute(['Alice', 30]) # True
stmt = db.prepare('SELECT * FROM users LIMIT 10')
stmt.execute() # True
row = stmt.fetch()
while row:
print('*', row['name'], row['age'])
row = stmt.fetch()
finally:
db.close()
if __name__ == '__main__':
main()
Asynchronous usage
Asyncronous usage is powered by awaiter.
The following example uses an asynchronous context manager, although the try - finally approach as above can still be used.
import asyncio
from sqlite3i import AsyncDatabase
async def main():
async with AsyncDatabase('example.db') as db:
stmt = db.prepare(
'CREATE TABLE IF NOT EXISTS users ('
' id INTEGER PRIMARY KEY,'
' name TEXT NOT NULL,'
' age INTEGER NOT NULL'
');'
)
await stmt.execute(timeout=30)
stmt = db.prepare(
'INSERT INTO users (name, age) VALUES (?, ?)'
)
await stmt.execute(['Alice', 30])
stmt = db.prepare('SELECT * FROM users LIMIT 10')
await stmt.execute()
row = await stmt.fetch()
while row:
print('*', row['name'], row['age'])
row = await stmt.fetch()
if __name__ == '__main__':
asyncio.run(main())
Install
python3 -m pip install --upgrade sqlite3i
License
MIT
Release files for sqlite3i 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlite3i-0.0.2.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlite3i-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.5 kB
Release files / sqlite3i-0.0.2.tar.gz
| Download URL | sqlite3i-0.0.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
953a59ca7d342455d98675833e5b3bce8381b84b855b24062ac1a9cd69aec033
|
|
BLAKE2b-256 checksum How to use checksums |
9c44961d84020038cc9f1f9833e8ea9c48979f192dbc9fb3d6e66ef2419c2c4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|
Release files / sqlite3i-0.0.2-py3-none-any.whl
| Download URL | sqlite3i-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83500e5ffb9de8e164c3da669bbdbfcec57b56a01957f93cbcb567f95db7fac5
|
|
BLAKE2b-256 checksum How to use checksums |
95f28d38dda9312fb72f565082a99111400cb209ef42e2c3eae43b20159b9b9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.9
|