db: Add initial SQL connection object
And set the row_factory to use the built-in sqlite3.Row so we can access columns by name in search results Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2e6c8a17e3
commit
2822a9ac35
|
@ -0,0 +1,12 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import lib
|
||||
import sqlite3
|
||||
|
||||
File = lib.data.emmental_data / "emmental.sqlite3"
|
||||
|
||||
Connection = sqlite3.connect(File)
|
||||
Connection.row_factory = sqlite3.Row
|
||||
|
||||
commit = Connection.commit
|
||||
execute = Connection.execute
|
||||
executemany = Connection.executemany
|
|
@ -0,0 +1,15 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import db
|
||||
import lib
|
||||
import sqlite3
|
||||
import unittest
|
||||
|
||||
class TestDB(unittest.TestCase):
|
||||
def test_db_init(self):
|
||||
self.assertEqual(db.File, lib.data.emmental_data / "emmental.sqlite3")
|
||||
self.assertIsInstance(db.Connection, sqlite3.Connection)
|
||||
self.assertEqual(db.Connection.row_factory, sqlite3.Row)
|
||||
|
||||
self.assertEqual(db.commit, db.Connection.commit)
|
||||
self.assertEqual(db.execute, db.Connection.execute)
|
||||
self.assertEqual(db.executemany, db.Connection.executemany)
|
Loading…
Reference in New Issue