Simple util from which I inherit my sqlite classes
Project description
Simple class that wraps around the sqlite3.conn().cursor().execute()
method
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_users(self, users):
# returns the number of inserted rows
return self._execute('INSERT OR IGNORE INTO Users (user_id, first_name) VALUES (?, ?)', users, rowcount=True, many=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()
params = [(1, 'Bob'), (2, 'Charlie')]
rows_inserted = db.insert_users(params)
print('Rows inserted:', rows_inserted)
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.8.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for simplesqlitewrap-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af156b4ef1727c1e4682dfac4e38baa931fe0c1f01e565e0cd1804d92d8f858 |
|
MD5 | 1343fab9391d158ce2f27d248fabbcde |
|
BLAKE2b-256 | ff8390e1856bef8615cac1eb7478ec8823dad6ea7d1a206e120b71e23d94b69d |