Skip to content

Instantly share code, notes, and snippets.

@chankeypathak
Created April 27, 2017 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chankeypathak/2a6336c8b7f063a1b2ce9c292e37e249 to your computer and use it in GitHub Desktop.
Save chankeypathak/2a6336c8b7f063a1b2ce9c292e37e249 to your computer and use it in GitHub Desktop.
Generic SQLite class in Python
class SqliteDB:
def __init__(self):
self.parent_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
self.db_path = os.path.join(self.parent_directory, 'db.sqlite3')
self.db_connection = sqlite3.connect(self.db_path)
self.db_cursor = self.db_connection.cursor()
def execute(self, query, args=''):
return self.db_cursor.execute(query, args)
def commit(self):
self.db_connection.commit()
def close(self):
self.db_connection.close()
if __name__ == '__main__':
database = SqliteDB()
@chankeypathak
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment