Metadata-Version: 2.4
Name: devdb-sql-python
Version: 1.0.2
Summary: Lightweight SQLite SDK with a MongoDB-like developer experience
Author: Mahadev
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Dev SQL — Python

Python port of the Dev SQL JavaScript SDK.

It provides a MongoDB-like API while using SQLite internally. Application code does not need to write SQL.

## Install 

```bash
pip install devdb
```

## Usage

```python
from dev_sql import DB

db = DB("./data/file.db")

User = db.create("users", {
    "id": {
        "type": "integer",
        "primary": True,
        "autoIncrement": True
    },
    "name": {
        "type": "string",
        "required": True
    },
    "email": {
        "type": "string",
        "unique": True
    },
    "age": {
        "type": "integer",
        "default": 18
    },
    "active": {
        "type": "boolean"
    },
    "metadata": {
        "type": "json"
    }
})

user = User.insert({
    "name": "Mahadev",
    "email": "mahadev@gmail.com",
    "age": 20,
    "active": True,
    "metadata": {"role": "student"}
})

print(user)

print(User.find())
print(User.find({"age": {"$gte": 18}}))
print(User.find_by_id(user["id"]))

User.update_by_id(user["id"], {"age": 21})
User.delete_by_id(user["id"])

print(db.tables())

db.close()
```

## Supported types

- `string` -> SQLite `TEXT`
- `integer` -> SQLite `INTEGER`
- `number` -> SQLite `REAL`
- `boolean` -> SQLite `INTEGER`
- `date` -> SQLite `TEXT`
- `json` -> SQLite `TEXT`

## Query operators

- `$eq`
- `$ne`
- `$gt`
- `$gte`
- `$lt`
- `$lte`
- `$in`

Example:

```python
User.find({
    "age": {"$gt": 18},
    "name": "Mahadev"
})
```

## Query options

```python
User.find(
    {"age": {"$gte": 18}},
    {
        "orderBy": "age",
        "order": "desc",
        "limit": 10,
        "offset": 0
    }
)
```

## Methods

### DB

```python
DB(path)
db.create(name, schema)
db.tables()
db.show_tables()
db.drop(name)
db.close()
```

### Table

```python
table.insert(data)
table.find()
table.find(query)
table.find(query, options)
table.find_by_id(id)
table.find_all()
table.update_by_id(id, data)
table.delete_by_id(id)
table.drop()
```

JavaScript-style aliases are also available:

```python
table.findById()
table.findAll()
table.updateById()
table.deleteById()
```
