Skip to content

Commit

Permalink
update README with context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
icyveins7 committed Mar 8, 2024
1 parent 98d68b9 commit 73fa114
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sew ![GitHub Workflow Status (with event)](https://github.com/icyveins7/sew/actions/workflows/run-unit-tests.yml/badge.svg) ![Github AutoPkg Workflow Status](https://github.com/icyveins7/sew/actions/workflows/auto-package.yml/badge.svg)

Sqlite Extensions & Wrappers for Python.
SQLite Extensions & Wrappers for Python.

Tired of writing create/insert/select statements yourself? Or maybe you'd just like to access your tables with keys like a Pythonic dictionary? Then just subclass this.

Expand Down Expand Up @@ -64,6 +64,24 @@ d.executemany() # Same as d.cur.executemany
d.commit() # Same as d.con.commit
```

You also get a context manager for free:

```python
with sew.Database(":memory:") as db:
db.execute("create table tbl(col INTEGER))")

# db connect is now closed i.e. .close() called on db.con
# further statements to the cursor will result in sqlite3.ProgrammingError
db.execute("select * from tbl") # ERROR

# This is unlike the default sqlite3 connection which allows this
with sq.connect(":memory:") as sqcon:
sqcur = sqcon.cursor()
sqcur.execute("create table tbl(col INTEGER))")

sqcur.execute("select * from tbl") # This is allowed, sqcon is still valid!
```

But the main benefit is in shortened requirements for database changes. Docstrings are available for most common methods.

As an example, instead of writing the whole statements, you can do the following:
Expand Down

0 comments on commit 73fa114

Please sign in to comment.