Simple util from which I inherit my sqlite classes
Project description
Simple SQLite wrapper
Example:
from simplesqlitewrap import Database
class DbWrapper(Database):
def __init__(self, file_path):
Database.__init__(self, file_path)
def create_tables(self):
self._execute('CREATE TABLE IF NOT EXISTS Users (user_id INTEGER PRIMARY KEY, first_name NVARCHAR);')
def insert_user(self, user_id, first_name):
# returns the number of inserted rows
return self._execute('INSERT OR IGNORE INTO Users VALUES (?, ?)', (user_id, first_name), rowcount=True)
def select_users(self, **kwargs):
# returns the list of all the recors in 'Users' as classes
return self._execute('SELECT * FROM Users', **kwargs)
db = DbWrapper('database.sqlite')
print(db)
db.create_tables()
print(db.insert_user(1, 'Bob'))
users = db.select_users(as_obj=True)
for user in users:
print('ID:', user.id, 'first name:', user.first_name)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplesqlitewrap-0.1.5.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for simplesqlitewrap-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd68ab5c15b5b3e74707bdff9223b823afc9b4526fe0d53031beb230087718c1 |
|
MD5 | cb3410a59907ecf576305996eab01f64 |
|
BLAKE2b-256 | 88f294a3d5bdd75bccc7fce98dd5d72adbfdefa547eed6c5bfcf4f73de3d7fb5 |