Skip to content

Commit

Permalink
Added support for relative paths via pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieran-Lock committed Aug 22, 2023
1 parent 06bd2d4 commit 0148e6f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<absolute_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
database = Database(Path("<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)
Expand Down Expand Up @@ -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("<database_path>.db"), output=False)


@table(database)
Expand Down
3 changes: 2 additions & 1 deletion schema.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 3 additions & 2 deletions sqliteframe/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0148e6f

Please sign in to comment.