https://github.com/arturogonzalezm/streamlit_crud
https://github.com/arturogonzalezm/streamlit_crud
python3 python311 streamlit streamlit-webapp
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arturogonzalezm/streamlit_crud
- Owner: arturogonzalezm
- License: mit
- Created: 2024-06-11T02:49:02.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-06-11T03:23:06.000Z (11 months ago)
- Last Synced: 2025-01-02T08:14:37.418Z (4 months ago)
- Topics: python3, python311, streamlit, streamlit-webapp
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://codecov.io/gh/arturogonzalezm/update_snowflake_tables_from_streamlit)
[](https://github.com/arturogonzalezm/update_snowflake_tables_from_streamlit/actions/workflows/workflow.yml)
[](https://opensource.org/licenses/MIT)# StreamLit CRUD App
This project is a Streamlit application for editing Snowflake tables. The application allows users to select a table from Snowflake, edit the data, and apply changes (update, insert, delete) directly to the Snowflake database.
## Project Structure
```python
streamlit_crud/
│
├── app.py
├── backend/
│ ├── init.py
│ ├── data_operations.py
│ ├── snowflake_connection.py
│ └── sql_statements.py
├── tests/
│ ├── init.py
│ ├── test_data_operations.py
│ ├── test_snowflake_connection.py
│ └── test_sql_statements.py
```## Sequence Diagram
```mermaid
sequenceDiagram
participant User
participant StreamlitApp
participant DataOperations
participant SQLStatements
participant SnowflakeConnectionUser->>StreamlitApp: Select Table
StreamlitApp->>DataOperations: get_tables()
DataOperations->>SnowflakeConnection: session
SnowflakeConnection-->>DataOperations: return session
DataOperations-->>StreamlitApp: return tablesUser->>StreamlitApp: Edit Data
StreamlitApp->>DataOperations: get_dataset(tabname)
DataOperations->>SnowflakeConnection: session
SnowflakeConnection-->>DataOperations: return session
DataOperations-->>StreamlitApp: return datasetUser->>StreamlitApp: Submit Changes
StreamlitApp->>SQLStatements: process_cols(edited_rows)
StreamlitApp->>SQLStatements: select_cols(dataset, idx)
StreamlitApp->>SQLStatements: insert_cols(added_rows, tabname)
StreamlitApp->>SQLStatements: delete_cols(idx, dataset, tabname)
SQLStatements-->>StreamlitApp: return SQL statementsStreamlitApp->>SnowflakeConnection: Execute SQL Statements
SnowflakeConnection-->>StreamlitApp: return execution resultStreamlitApp->>User: Display Success/Error Message
```### Files Description
- `main.py`: The main Streamlit application file that includes the UI for selecting and editing Snowflake tables.
- `backend/`: Directory containing the backend logic.
- `__init__.py`: Indicates that the directory is a Python package.
- `data_operations.py`: Functions for interacting with Snowflake tables (e.g., `get_dataset`, `get_tables`).
- `snowflake_connection.py`: Singleton class for managing the Snowflake connection.
- `sql_statements.py`: Functions for generating SQL statements (e.g., `process_cols`, `select_cols`, `insert_cols`, `delete_cols`).
- `tests/`: Directory containing the unit tests.
- `__init__.py`: Indicates that the directory is a Python package.
- `test_data_operations.py`: Unit tests for the `data_operations.py` module.
- `test_snowflake_connection.py`: Unit tests for the `snowflake_connection.py` module.
- `test_sql_statements.py`: Unit tests for the `sql_statements.py` module.## Running the Application
To run the Streamlit application, execute the following command in your terminal:
```sh
streamlit run app.py
```This will start the Streamlit server and open the application in your default web browser.
## Running the Tests
To run the unit tests, execute the following command in your terminal:
```sh
pytest
```This will run all the tests in the `tests/` directory and display the results in the terminal.
## Class Diagram
```mermaid
classDiagram
class SnowflakeConnection {
-session: Session
+session: Session
+_create_session(): Session
}class data_operations {
+get_dataset(table_name: str): DataFrame
+get_tables(): DataFrame
}class sql_statements {
+process_cols(columns: dict): str
+select_cols(df: DataFrame, idx: int): str
+insert_cols(cols: dict, tabname: str): str
+delete_cols(idx: int, df: DataFrame, tabname: str): str
}SnowflakeConnection --> data_operations : Uses
SnowflakeConnection --> sql_statements : Uses
```## License
This project is licensed under the terms of the MIT license.