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 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_namedtuple=True)
for user in users:
print('ID:', user.id, 'first name:', user.first_name)
Disclaimer
If you stumbled upon this package, please remember that this is just a small utility I made for myself - breaking changes may be introduced without notice
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
Built Distribution
Close
Hashes for simplesqlitewrap-0.1.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d795ee5dccc07739b64466c8be3369cfed30ea67dd19efd8b1d3f093fc62131a |
|
MD5 | 5697980e07a3e0858000646da179925d |
|
BLAKE2b-256 | 0056ef8f3a61c302d8b647f4895bb1689167a6b61879651083d0922b2e3bf05d |