Skip to content

Commit 5d445dd

Browse files
committed
DB Connection Registry Validation, Better Inheritance, Table Methods
1 parent 6cebf57 commit 5d445dd

File tree

3 files changed

+228
-74
lines changed

3 files changed

+228
-74
lines changed

stat_log_db/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "stat-log-db"
77
version = "0.0.1"
88
description = ""
99
readme = "README.md"
10-
requires-python = "==3.12.10"
10+
requires-python = ">=3.12.10"
1111
dependencies = [
1212
]
1313

stat_log_db/src/stat_log_db/cli.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33

44
from .parser import create_parser
5-
from .db import Database, BaseConnection
5+
from .db import Database, MemDB, FileDB, BaseConnection
66

77

88
def main():
@@ -18,19 +18,18 @@ def main():
1818

1919
# print(f"{args=}")
2020

21-
db_filename = 'sl_db.sqlite'
22-
sl_db = Database(db_filename)
23-
con = sl_db.init_db(False)
24-
if isinstance(con, BaseConnection):
25-
con.execute("CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY, message TEXT);")
26-
con.execute("INSERT INTO logs (message) VALUES (?);", ("Hello, world!",))
27-
con.commit()
28-
con.execute("SELECT * FROM logs;")
29-
sql_logs = con.fetchall()
30-
print(sql_logs)
31-
21+
sl_db = MemDB(":memory:", True, True)
22+
con = sl_db.init_db(True)
23+
con.create_table("test", [('notes', 'TEXT')], False, True)
24+
con.execute("INSERT INTO test (notes) VALUES (?);", ("Hello world!",))
25+
con.commit()
26+
con.execute("SELECT * FROM test;")
27+
sql_logs = con.fetchall()
28+
print(sql_logs)
29+
con.drop_table("test", True)
3230
sl_db.close_db()
33-
# os.remove(db_filename)
31+
if sl_db.is_file:
32+
os.remove(sl_db.file_name)
3433

3534
if __name__ == "__main__":
3635
main()

0 commit comments

Comments
 (0)