Skip to content

Commit 649a258

Browse files
Antony BaileyAntony Bailey
authored andcommitted
docs
1 parent 301e77e commit 649a258

File tree

4 files changed

+668
-27
lines changed

4 files changed

+668
-27
lines changed

API.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# pySQLY API Documentation
2+
3+
This document provides detailed information about the pySQLY API.
4+
5+
## Table of Contents
6+
7+
- [SQLYExecutor](#sqlyexecutor)
8+
- [SQLYParser](#sqlyparser)
9+
- [SQLYUtils](#sqlyutils)
10+
- [Database Connectors](#database-connectors)
11+
- [IDBConnector](#idbconnector)
12+
- [BaseDBConnector](#basedbconnector)
13+
- [Specific Connectors](#specific-connectors)
14+
- [Error Handling](#error-handling)
15+
16+
## SQLYExecutor
17+
18+
The central class for executing SQLY queries.
19+
20+
### Constructor
21+
22+
```python
23+
SQLYExecutor(datasource, db_type=None)
24+
```
25+
26+
**Parameters:**
27+
28+
- `datasource`: Connection string or path to the database
29+
- `db_type`: Type of database ("sqlite", "mariadb", "postgres", "oracle", "mssql")
30+
31+
### SQLYExecutor Methods
32+
33+
#### execute
34+
35+
```python
36+
execute(query: str) -> Any
37+
```
38+
39+
Executes a SQLY query string.
40+
41+
**Parameters:**
42+
43+
- `query`: A SQLY query in YAML format
44+
45+
**Returns:**
46+
47+
- Results from the database query execution
48+
49+
**Raises:**
50+
51+
- `SQLYExecutionError`: If execution fails
52+
- `SQLYParseError`: If the YAML cannot be parsed
53+
54+
**Example:**
55+
56+
```python
57+
executor = SQLYExecutor("mydb.sqlite", "sqlite")
58+
results = executor.execute("""
59+
select:
60+
- name
61+
- age
62+
from: users
63+
where:
64+
- field: age
65+
operator: ">"
66+
value: 18
67+
""")
68+
```
69+
70+
## SQLYParser
71+
72+
Handles parsing of SQLY query strings into structured dictionaries.
73+
74+
### SQLYParser Methods
75+
76+
#### parse
77+
78+
```python
79+
SQLYParser.parse(query: str) -> dict
80+
```
81+
82+
**Parameters:**
83+
84+
- `query`: SQLY query string in YAML format
85+
86+
**Returns:**
87+
88+
- Dictionary representation of the YAML query
89+
90+
**Raises:**
91+
92+
- `SQLYParseError`: If the YAML cannot be parsed
93+
94+
## SQLYUtils
95+
96+
Utility functions for SQLY operations.
97+
98+
### SQLYUtils Methods
99+
100+
#### validate_query
101+
102+
```python
103+
SQLYUtils.validate_query(query: dict) -> bool
104+
```
105+
106+
Validates if a query dictionary has all required fields.
107+
108+
**Parameters:**
109+
110+
- `query`: Dictionary representation of a SQLY query
111+
112+
**Returns:**
113+
114+
- `True` if valid, `False` otherwise
115+
116+
#### translate_to_sql
117+
118+
```python
119+
SQLYUtils.translate_to_sql(query: dict) -> tuple[str, list]
120+
```
121+
122+
Converts a SQLY dictionary to a SQL query string and parameters.
123+
124+
**Parameters:**
125+
126+
- `query`: Dictionary representation of a SQLY query
127+
128+
**Returns:**
129+
130+
- Tuple with SQL query string and parameter list
131+
132+
## Database Connectors
133+
134+
### IDBConnector
135+
136+
Interface for all database connectors.
137+
138+
#### IDBConnector Methods
139+
140+
##### execute_sql
141+
142+
```python
143+
execute(sql, params) -> Any
144+
```
145+
146+
Abstract method that must be implemented by all connectors.
147+
148+
### BaseDBConnector
149+
150+
Base implementation of the IDBConnector interface.
151+
152+
#### BaseDBConnector Methods
153+
154+
##### execute_query
155+
156+
```python
157+
execute_query(query: dict) -> Any
158+
```
159+
160+
Executes a query dictionary against the database.
161+
162+
##### execute
163+
164+
```python
165+
execute(sql, params) -> Any
166+
```
167+
168+
Executes raw SQL with parameters.
169+
170+
### Specific Connectors
171+
172+
pySQLY includes the following database-specific connectors:
173+
174+
- `SQLiteConnector`: For SQLite databases
175+
- `MariaDBConnector`: For MariaDB/MySQL databases
176+
- `PostgresConnector`: For PostgreSQL databases
177+
- `OracleConnector`: For Oracle databases
178+
- `MSSQLConnector`: For Microsoft SQL Server databases
179+
180+
Each connector inherits from `BaseDBConnector` and may include database-specific optimizations.
181+
182+
## Error Handling
183+
184+
pySQLY defines a hierarchy of exception classes for error handling:
185+
186+
- `SQLYError`: Base exception class for all pySQLY errors
187+
- `SQLYParseError`: Raised when parsing a SQLY query fails
188+
- `SQLYExecutionError`: Raised when executing a query fails
189+
190+
**Example:**
191+
192+
```python
193+
from pysqly import SQLYExecutor, SQLYParseError, SQLYExecutionError
194+
195+
try:
196+
executor = SQLYExecutor("mydb.sqlite", "sqlite")
197+
results = executor.execute(query)
198+
except SQLYParseError as e:
199+
print(f"Error parsing query: {e}")
200+
except SQLYExecutionError as e:
201+
print(f"Error executing query: {e}")
202+
```
203+
204+
For more detailed examples, see the [Examples](./EXAMPLES.md) document.

CONTRIBUTING.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Contributing to pySQLY
2+
3+
Thank you for your interest in contributing to pySQLY! This document provides guidelines and instructions for contributing to this project.
4+
5+
## Table of Contents
6+
7+
- [Code of Conduct](#code-of-conduct)
8+
- [Getting Started](#getting-started)
9+
- [Development Workflow](#development-workflow)
10+
- [Coding Standards](#coding-standards)
11+
- [Testing](#testing)
12+
- [Submitting Changes](#submitting-changes)
13+
- [Issue Reporting](#issue-reporting)
14+
15+
## Code of Conduct
16+
17+
This project adheres to a [Code of Conduct](CODE_OF_CONDUCT.md) that all contributors are expected to follow. Please read it before participating.
18+
19+
## Getting Started
20+
21+
### Prerequisites
22+
23+
- Python 3.9 or newer
24+
- Git
25+
26+
### Setting Up Your Development Environment
27+
28+
1. Fork the repository on GitHub
29+
2. Clone your fork locally:
30+
31+
```bash
32+
git clone https://github.com/yourusername/pySQLY.git
33+
cd pySQLY
34+
```
35+
36+
3. Create a virtual environment and install dependencies:
37+
38+
```bash
39+
python -m venv venv
40+
source venv/bin/activate # On Windows, use: venv\Scripts\activate
41+
pip install -e . # Install in development mode
42+
pip install -r requirements.txt
43+
```
44+
45+
4. Set up pre-commit hooks:
46+
47+
```bash
48+
pip install pre-commit
49+
pre-commit install
50+
```
51+
52+
## Development Workflow
53+
54+
1. Create a new branch for your feature or bugfix:
55+
56+
```bash
57+
git checkout -b feature/your-feature-name
58+
```
59+
60+
2. Make your changes and ensure they follow the project's coding standards.
61+
62+
3. Write tests for your changes.
63+
64+
4. Run the test suite:
65+
66+
```bash
67+
pytest
68+
```
69+
70+
5. Commit your changes with a descriptive message:
71+
72+
```bash
73+
git commit -m "Add feature: your feature description"
74+
```
75+
76+
## Coding Standards
77+
78+
pySQLY follows these coding standards:
79+
80+
- We use [Black](https://github.com/psf/black) for code formatting
81+
- We follow [PEP 8](https://www.python.org/dev/peps/pep-0008/) for style guidelines
82+
- We use [isort](https://pycqa.github.io/isort/) for import sorting
83+
- We use [Ruff](https://github.com/astral-sh/ruff) for linting
84+
85+
These tools are configured in the project and run automatically with pre-commit hooks.
86+
87+
## Documentation
88+
89+
- Use docstrings for all public modules, functions, classes, and methods
90+
- Follow [Google Style Python Docstrings](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)
91+
- Update documentation when changing functionality
92+
93+
## Testing
94+
95+
- Write tests for all new features and bug fixes
96+
- Maintain or improve test coverage with each contribution
97+
- Tests are written using pytest
98+
99+
To run tests:
100+
101+
```bash
102+
pytest
103+
```
104+
105+
For test coverage:
106+
107+
```bash
108+
pytest --cov=pysqly
109+
```
110+
111+
## Submitting Changes
112+
113+
1. Push your changes to your fork:
114+
115+
```bash
116+
git push origin feature/your-feature-name
117+
```
118+
119+
2. Create a Pull Request (PR) from your fork to the main repository.
120+
121+
3. In your PR description:
122+
- Clearly describe the problem and solution
123+
- Include the relevant issue number if applicable
124+
- Mention if it changes external behavior
125+
126+
## Issue Reporting
127+
128+
- Use the GitHub issue tracker to report bugs or request features
129+
- For bugs, include:
130+
- Steps to reproduce
131+
- Expected behavior
132+
- Actual behavior
133+
- Python and pySQLY versions
134+
- Operating system
135+
- Any relevant error messages or logs
136+
137+
## Versioning
138+
139+
We use [Semantic Versioning](https://semver.org/) for version numbers:
140+
141+
- MAJOR version for incompatible API changes
142+
- MINOR version for backward-compatible new features
143+
- PATCH version for backward-compatible bug fixes
144+
145+
Thank you for contributing to pySQLY!

0 commit comments

Comments
 (0)