Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Thanks for your interest in contributing!
2. Create a virtual environment: python -m venv .venv && source .venv/bin/activate
3. Install dev dependencies: pip install -e ".[dev]"
4. Run tests: pytest tests/ -v
5. Lint: uff check src/
5. Lint: `ruff check src/`

## Pull Requests

- Fork the repo and create a feature branch
- Add tests for any new functionality
- Ensure all existing tests pass
- Run uff check src/ --fix before committing
- Run `ruff check src/ --fix` before committing
- Keep PRs focused on a single change

## Reporting Issues
Expand Down
Binary file removed src/json2sql/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/cli.cpython-312.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/cli.cpython-314.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/converter.cpython-312.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/converter.cpython-314.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/dialects.cpython-312.pyc
Binary file not shown.
Binary file removed src/json2sql/__pycache__/dialects.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
50 changes: 50 additions & 0 deletions tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,59 @@ def test_generate_schema(self, converter_postgres):
assert "CREATE TABLE" in result
assert "INSERT INTO" not in result

def test_generate_schema_single_object(self, converter_postgres):
"""Single dict root generates schema correctly."""
data = json.dumps({"name": "Alice", "age": 30})
result = converter_postgres.generate_schema(data, table_name="users")
assert "CREATE TABLE" in result
assert "name" in result
assert "age" in result
assert "INSERT INTO" not in result

def test_generate_schema_primitive(self, converter_postgres):
"""Primitive root type falls back to 'value' column."""
data = json.dumps("hello")
result = converter_postgres.generate_schema(data, table_name="single")
assert "CREATE TABLE" in result
assert "value" in result

def test_generate_schema_with_flatten(self):
"""Schema generation with flatten=True and nested arrays."""
conv = JSONToSQLConverter(dialect=Dialect.POSTGRES, flatten=True)
data = json.dumps({
"id": 1,
"orders": [
{"product": "Widget", "qty": 3},
],
})
result = conv.generate_schema(data, table_name="users")
assert "CREATE TABLE" in result
# Should create a separate table for nested array
assert "users_orders" in result or "orders" in result
assert "INSERT INTO" not in result


# --- Edge cases ---

class TestUnsupportedRootTypes:
"""Tests for behavior with unsupported root JSON types."""

def test_convert_string_root_raises(self, converter_postgres):
"""A plain string as JSON root raises ValueError."""
with pytest.raises(ValueError, match="Unsupported JSON root type"):
converter_postgres.convert(json.dumps("just a string"), table_name="t")

def test_convert_number_root_raises(self, converter_postgres):
"""A plain number as JSON root raises ValueError."""
with pytest.raises(ValueError, match="Unsupported JSON root type"):
converter_postgres.convert(json.dumps(42), table_name="t")

def test_convert_boolean_root_raises(self, converter_postgres):
"""A plain boolean as JSON root raises ValueError."""
with pytest.raises(ValueError, match="Unsupported JSON root type"):
converter_postgres.convert(json.dumps(True), table_name="t")


class TestEdgeCases:
def test_string_with_quotes(self, converter_postgres):
data = json.dumps({"bio": "It's a test"})
Expand Down