mirror of
http://git.k-space.ee/arti/doors.git
synced 2024-10-13 16:30:58 +03:00
Teach DB to create schema in existing connection
This commit is contained in:
parent
ea3d617e9c
commit
7878cadb30
@ -51,6 +51,9 @@ class DB:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_db(dbfile):
|
def create_db(dbfile):
|
||||||
|
if type(dbfile) is DB:
|
||||||
|
db = dbfile.db
|
||||||
|
else:
|
||||||
db = sqlite3.connect(dbfile)
|
db = sqlite3.connect(dbfile)
|
||||||
db.executescript("""
|
db.executescript("""
|
||||||
create table versions (
|
create table versions (
|
||||||
|
@ -4,9 +4,15 @@ from kdoorweb.db import DB
|
|||||||
|
|
||||||
|
|
||||||
class TestDB(unittest.TestCase):
|
class TestDB(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.db = DB()
|
||||||
|
|
||||||
def test_create_db_in_memory(self):
|
def test_create_db_in_memory(self):
|
||||||
DB.create_db(dbfile=":memory:")
|
DB.create_db(dbfile=":memory:")
|
||||||
|
|
||||||
|
def test_create_db_in_connection(self):
|
||||||
|
DB.create_db(dbfile=self.db)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user