mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-10 14:06:43 +00:00
Add drop table
This commit is contained in:
parent
a7b1a6e1ec
commit
5275c332cc
@ -283,6 +283,13 @@ class PersistentState:
|
|||||||
def __getitem__(self, table):
|
def __getitem__(self, table):
|
||||||
return self._table_factory(self, table)
|
return self._table_factory(self, table)
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
with sqlite3.connect(self.dbfile, **self.dbargs) as conn:
|
||||||
|
try:
|
||||||
|
conn.execute(f"DROP TABLE {key}")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def pg_fetch_cursor_all(cur, name, batch_size=1000):
|
def pg_fetch_cursor_all(cur, name, batch_size=1000):
|
||||||
while True:
|
while True:
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.82",
|
version="1.83",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
|
@ -131,3 +131,13 @@ class TestPersistentState(TestCase):
|
|||||||
s["a"][0] = {"x": b'abc'}
|
s["a"][0] = {"x": b'abc'}
|
||||||
|
|
||||||
self.assertEqual(list(s["a"])[0]["x"], b'abc')
|
self.assertEqual(list(s["a"])[0]["x"], b'abc')
|
||||||
|
|
||||||
|
def test_drop_table(self):
|
||||||
|
s = PersistentState()
|
||||||
|
|
||||||
|
s["a"][0] = {"x": 1}
|
||||||
|
s["a"][1] = {"x": 2}
|
||||||
|
self.assertEqual(len(list(s["a"])), 2)
|
||||||
|
|
||||||
|
del s["a"]
|
||||||
|
self.assertEqual(len(list(s["a"])), 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user