Skip to content

Commit f039e42

Browse files
committed
added unit tests. Added create_sqlite_db() function
1 parent 3aedc5b commit f039e42

25 files changed

+388
-98
lines changed

.githubworkflowstest.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Run Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# Checkout the repository
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
# Set up Python environment
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.7" # Use the Python version your project requires
25+
26+
# Install dependencies
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -r requirements.txt
31+
32+
# Run unit tests
33+
- name: Run tests
34+
run: |
35+
python -m unittest discover

README.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# SQLite Query Manager
22

3-
`sqlite_query_manager` is a Python package designed to efficiently manage and
3+
`sqlite_manager` is a Python package designed to efficiently manage and
44
execute SQL queries on SQLite databases. The package supports organizing SQL queries in directories, running them sequentially or selectively, and exporting the results as CSV files. It also includes flexible options to rerun all queries, specific queries, or skip those with existing outputs.
55

66
## Table of Contents
77

88
- [Introduction](#introduction)
99
- [Usage](#usage)
10-
- [Basic Example](#basic-example)
1110
- [Directory Layouts](#directory-layouts)
1211
- [Installation](#installation)
1312

1413
---
1514

1615
## Introduction
1716

18-
The `sqlite_query_manager` package simplifies SQL query execution workflows by:
17+
The `sqlite_manager` package simplifies SQL query execution workflows by:
1918
- Recursively processing SQL queries from directories.
2019
- Mirroring directory structures for outputs.
2120
- Avoiding redundant execution of queries unless explicitly specified.
@@ -27,12 +26,49 @@ This makes it ideal for projects involving multiple interdependent queries, such
2726

2827
## Usage
2928

30-
### Basic Example
29+
### `create_sqlite_db` function:
3130

32-
Here’s a minimal example of how to use the `run_sql_queries` function:
31+
```python
32+
# Import necessary modules
33+
import pandas as pd
34+
from sqlite_manager import create_sqlite_db
35+
36+
# Example DataFrame
37+
data = {
38+
"id": [1, 2, 3],
39+
"name": ["Alice", "Bob", "Charlie"],
40+
"age": [25, 30, 35]
41+
}
42+
df = pd.DataFrame(data)
43+
44+
# Path to schema file (must contain the table definition)
45+
schema_file = "db_schema.sql"
46+
47+
# Example schema (contents of db_schema.sql)
48+
# CREATE TABLE ExampleTable (
49+
# id INTEGER PRIMARY KEY,
50+
# name TEXT,
51+
# age INTEGER
52+
# );
53+
54+
# Path to SQLite database file
55+
db_file = "example_database.db"
56+
57+
# Create SQLite database from the DataFrame
58+
create_sqlite_db(
59+
df,
60+
schema_file,
61+
db_file
62+
)
63+
64+
# Verify: The database is created, and data is inserted into the ExampleTable.
65+
print(f"Database '{db_file}' created successfully with data from the DataFrame.")
66+
```
67+
68+
### `run_sql_queries` function:
3369

3470
```python
35-
from sqlite_query_manager import run_sql_queries
71+
from sqlite_manager import run_sql_queries
3672

3773
query_dir = "sql_queries" # Directory containing SQL files
3874
db_file = "data/online_retail.db" # SQLite database file
@@ -92,10 +128,10 @@ ensuring a clean and organized workflow.
92128
Install directly from GitHub:
93129

94130
```bash
95-
pip install git+https://github.com/Thomas-Rauter/sqlite_query_manager[email protected]
131+
pip install git+https://github.com/Thomas-Rauter/sqlite_manager[email protected]
96132
```
97133

98134
## When facing problems
99135

100136
For any issues or feature requests, please open an issue on the [GitHub
101-
repository](https://github.com/Thomas-Rauter/sqlite_query_manager).
137+
repository](https://github.com/Thomas-Rauter/sqlite_manager).

requirements.txt

308 Bytes
Binary file not shown.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from setuptools import setup, find_packages
22

33
setup(
4-
name="sqlite_query_manager",
4+
name="sqlite_manager",
55
version="0.1.0",
6-
description="A package for managing SQL queries on SQLite databases",
6+
description="A package for managing SQLite operations",
77
long_description=open("README.md").read(),
88
long_description_content_type="text/markdown",
99
author="Thomas Rauter",

sqlite_manager/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .run_sql_queries import run_sql_queries
2+
from .create_sqlite_db import create_sqlite_db
3+
4+
__all__ = ["run_sql_queries", "create_sqlite_db"]

sqlite_query_manager/__pycache__/__init__.cpython-310.pyc renamed to sqlite_manager/__pycache__/__init__.cpython-310.pyc

File renamed without changes.
249 Bytes
Binary file not shown.
1.83 KB
Binary file not shown.
2.86 KB
Binary file not shown.

sqlite_query_manager/__pycache__/run_sql_queries.cpython-310.pyc renamed to sqlite_manager/__pycache__/run_sql_queries.cpython-310.pyc

5.37 KB
Binary file not shown.

0 commit comments

Comments
 (0)