Metadata-Version: 2.4
Name: dbe-engine
Version: 0.1.1
Summary: Lightweight, dependency-free database engine with Estonian-language SQL-like keywords (LOO TABEL, VALI, LISA TABELISSE, UUENDA, KUSTUTA), backed by a simple JSON file format.
Author-email: martin.mattias.tarkus1@gmail.com
License: MIT
Project-URL: Homepage, https://databaas.ee/
Project-URL: Live demo, https://databaas.ee/
Project-URL: API examples, https://databaas.ee/naited.html
Keywords: estonian,eesti,sql,database,education,õppevahend
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database
Classifier: Topic :: Education
Classifier: Natural Language :: Estonian
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# dbe-engine

Lightweight, dependency-free database engine with **Estonian-language**
SQL-like keywords, backed by a simple JSON file format (`.dbe`).

```
LOO TABEL kasutajad (id TÄISARV PÕHIVÕTI, nimi TEKST);
LISA TABELISSE kasutajad (id, nimi) VÄÄRTUSED (1, 'Mari');
VALI KÕIK TABELIST kasutajad KUS id = 1;
```

**Live demo, web UI and HTTP API:** https://databaas.ee/
(runnable code examples for PHP, Java, Python and Go: https://databaas.ee/naited.html)

## Install

```
pip install dbe-engine
```

## Usage

```python
from dbe_engine.engine import Database
from dbe_engine import storage

path = "minu.dbe"
storage.save(path, storage.empty_database())

db = Database(path)
results = db.execute_script(
    "LOO TABEL kasutajad (id TÄISARV PÕHIVÕTI, nimi TEKST);"
    "LISA TABELISSE kasutajad (id, nimi) VÄÄRTUSED (1, 'Mari');"
    "VALI KÕIK TABELIST kasutajad;"
)
for r in results:
    print(r)
```

## More examples

### Filtering, sorting and limiting

```python
db.execute_script(
    "LOO TABEL tooted (id TÄISARV PÕHIVÕTI, nimi TEKST, hind MURDARV, laos TÄISARV);"
    "LISA TABELISSE tooted (id, nimi, hind, laos) VÄÄRTUSED (1, 'Kohv', 4.5, 20);"
    "LISA TABELISSE tooted (id, nimi, hind, laos) VÄÄRTUSED (2, 'Tee', 3.2, 0);"
    "LISA TABELISSE tooted (id, nimi, hind, laos) VÄÄRTUSED (3, 'Kakao', 5.0, 8);"
)

# Only products in stock and cheaper than 5 euros, cheapest first
results = db.execute_script(
    "VALI nimi, hind TABELIST tooted KUS laos > 0 JA hind < 5 JÄRJESTA hind KASVAVALT;"
)
print(results[0]["rows"])  # [{'nimi': 'Kohv', 'hind': 4.5}]
```

### Updating and deleting

```python
db.execute_script(
    "UUENDA tooted MÄÄRA hind = 4.0, laos = 15 KUS nimi = 'Kohv';"
    "KUSTUTA TABELIST tooted KUS laos = 0;"
    "VALI KÕIK TABELIST tooted;"
)
```

### Multiple tables, NULLs, ORDER BY + LIMIT together

```python
db.execute_script(
    "LOO TABEL kliendid (id TÄISARV PÕHIVÕTI, nimi TEKST KOHUSTUSLIK, email TEKST);"
    "LOO TABEL tellimused (id TÄISARV PÕHIVÕTI, kliendi_id TÄISARV, summa MURDARV);"
    "LISA TABELISSE kliendid (id, nimi, email) VÄÄRTUSED (1, 'Mari Maasikas', TÜHI);"
    "LISA TABELISSE tellimused (id, kliendi_id, summa) VÄÄRTUSED (1, 1, 49.90);"
    "LISA TABELISSE tellimused (id, kliendi_id, summa) VÄÄRTUSED (2, 1, 120.50);"
    # biggest order overall
    "VALI KÕIK TABELIST tellimused JÄRJESTA summa KAHANEVALT PIIRA 1;"
    "NÄITA TABELEID;"
    "KIRJELDA tellimused;"
)
```

### Schema and table introspection

```python
db.execute_script("NÄITA TABELEID;")   # SHOW TABLES
db.execute_script("KIRJELDA tooted;")  # DESCRIBE
```

Every `execute_script()` call returns a list of per-statement results, each
shaped like `{"ok": True, "type": "rows"|"info", "columns"/"rows" or "message"/"error"}`
— the same JSON shape returned by the HTTP API on https://databaas.ee/.

## Supported commands

| Eesti keeles | SQL vaste |
|---|---|
| `LOO TABEL nimi (veerg TÜÜP [PÕHIVÕTI] [KOHUSTUSLIK], ...)` | `CREATE TABLE` |
| `KUSTUTA TABEL nimi` | `DROP TABLE` |
| `NÄITA TABELEID` | `SHOW TABLES` |
| `KIRJELDA nimi` | `DESCRIBE` |
| `LISA TABELISSE nimi (...) VÄÄRTUSED (...)` | `INSERT INTO` |
| `VALI veerud TABELIST nimi [KUS ...] [JÄRJESTA ...] [PIIRA ...]` | `SELECT` |
| `UUENDA nimi MÄÄRA veerg = väärtus [KUS ...]` | `UPDATE` |
| `KUSTUTA TABELIST nimi [KUS ...]` | `DELETE FROM` |

Types: `TÄISARV` (int), `MURDARV` (float), `TEKST` (text), `TÕEVÄÄRTUS` (bool).

## License

MIT
