diff --git a/README.md b/README.md index 91de7fe..0e7c2c2 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,10 @@ SQLiteFrame has **ZERO** external dependencies - it uses only the standard libra To create a table, use the template below. This will automatically run the CreateTable SQLite command for you: ```py from sqliteframe import Database, table, String, Integer, Boolean +from pathlib import Path -database = Database(".db", output=False) # When the output parameter is True, the formed SQL query will be outputted into the console as a string every time a query is executed +database = Database(Path(".db"), output=False) # When the output parameter is True, the formed SQL query will be outputted into the console as a string every time a query is executed @table(database) @@ -97,9 +98,10 @@ select_statement.execute() Linking tables can be done with Foreign Keys in SQLiteFrame: ```py from sqliteframe import Database, table, String, Integer, Boolean, ForeignKey +from pathlib import Path -database = Database("database.db", output=False) +database = Database(Path(".db"), output=False) @table(database) diff --git a/schema.py b/schema.py index d67278f..7827bd4 100644 --- a/schema.py +++ b/schema.py @@ -1,8 +1,9 @@ from sqliteframe import Database, table, String, Boolean, Date, Time, ForeignKey, Blob, Float, Integer from datetime import date, time +from pathlib import Path -database = Database("database.db", output=True) +database = Database(Path("./database.db"), output=True) @table(database) diff --git a/sqliteframe/database.py b/sqliteframe/database.py index b99fcd1..1f4909a 100644 --- a/sqliteframe/database.py +++ b/sqliteframe/database.py @@ -6,6 +6,7 @@ from dataclasses import dataclass, field from contextlib import contextmanager from sqlite3 import connect, Cursor, Connection +from pathlib import Path from .entity import Entity from .statements import Statement, Pragma from .pragma import PragmaStatements @@ -25,7 +26,7 @@ class Database: :param foreign_keys: Whether to enable foreign key relations in this database initially """ - path: str + path: Path output: bool = False foreign_keys: bool = True tables: set[Entity] = field(init=False, default_factory=set) @@ -113,7 +114,7 @@ def connect(self, commit: bool = True) -> Connection: if self.connected: self.connections.append(commit) return self.db_connection - self.db_connection = connect(self.path) + self.db_connection = connect(str(self.path.resolve())) self.connections.append(commit) self.cursor = self.db_connection.cursor() if self.foreign_keys: