-
Notifications
You must be signed in to change notification settings - Fork 0
class PandaSQLiteDB
Marcel Ferrari edited this page Mar 2, 2023
·
5 revisions
The PandaSQLiteDB class is the main interface for managing and storing data in the underlying SQLite database.
PandaSQLite(db_path: str, auto_commit: bool = True, verbose: bool = False)
-
db_path
: path to the database. If the database does not exist it will be created. -
auto_commit
: auto commit after each operation on the database. This option ensures that the updates to the database are saved periodically after each operation. If this feature is disable it is important to call thecommit()
method before the program terminates (or the Jupyter notebook is closed). - 'verbose': enable verbosity. This option enables print statements when executing SQL queries.
- query(query: str) -> pd.DataFrame: query database and return result as DataFrame
- execute(statement: str) -> None: execute SQL statement with no return data
-
get_table(tname: str) -> pd.DataFrame: get whole table. Equivalent to querying
SELECT * FROM tname
. - create_table(tname: str, df: pd.DataFrame, if_exists='fail') -> None: create table from DataFrame.
- update_table(tname: str, df: pd.DataFrame) -> None: update table with values in DataFrame.
- replace_table(tname: str, df: pd.DataFrame) -> None: replace table with new table from Dataframe.
- append_to_table(tname: str, df: pd.DataFrame) -> None: append data from DataFrame to table.
- delete_table(tname: str) -> None: Delete table.
- show_tables() -> pd.DataFrame: show all names of tables in the database.
- commit() -> None: commit changes to database.
- import_data(tname: str, fpath: str, format: str, if_exists='fail', **kwargs) -> None: import data from file.
- import_db(other, if_exists = 'fail', **kwargs): import external database
# Open database "example.sql"
db = PandaSQLDB("example.sql")
# Open database "example.sql" with auto-commit disabled and verbosity enabled
db = PandaSQLDB("example.sql", auto_commit = False, verbose = True)