Metadata-Version: 2.3
Name: sqladaptor
Version: 0.2.1
Summary: Starting adaptor for JSON/Pandas to SQL db
Author-email: Bosco Ho <apposite@gmail.com>
Requires-Python: >=3.8
Requires-Dist: fastjsonschema>=2.19.1
Requires-Dist: pandas>=2.2.2
Requires-Dist: path>=16.14.0
Requires-Dist: pydash>=8.0.1
Requires-Dist: pytest>=8.2.1
Requires-Dist: rich>=13.7.1
Requires-Dist: ruff-lsp>=0.0.53
Requires-Dist: ruff>=0.4.5
Description-Content-Type: text/markdown

# sqladaptor

Transferring data, stored as JSON or Pandas, into an SQL database and back again.

## Why?

Building webserver protoytpes, you will often save your data as JSON or Pandas files.
At some point though, you will want to transition to a database where
updating/inserting data to disk is more efficient. 

SqlAdaptor allows an easy transition to such a database.
This includes methods to search using dicts, and
to return rows as dicts for web-servers. 

This is possible
because there is an equivalence between JSON dict lists, Pandas DataFrames
and SQL tables - they are all tabular arrangements of columnar data.

## Installation

```bash
pip install sqladaptor
```

## Basic Usage

```python
from sqladaptor.sqlite import SqliteAdaptor
import pandas

entries = [
    {"description": "this", "value": 1},
    {"description": "that", "value": 2}
]

db = SqliteAdaptor('db.sqlite')
db.set_from_df('data1', pandas.DataFrame(entries))

entries = db.get_dicts('data1')
# [
#   {'description': 'this', 'value': 1}, 
#   {'description': 'that', 'value': 2}
# ]

return_entries = db.get_dicts('data1', {"description": "this"})
# [{'description': 'this', 'value': 1}]

df = db.get_df("data1", {"value": 2})
#   description  value
# 0        that      2

db.update("data1", {"value": 2}, {"description": "altered"})
return_entries2 = db.get_dicts('data1', {"value": 2})
# [{'description': 'altered', 'value': 2}]
```
