simple-orm-sqlite


Namesimple-orm-sqlite JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryBasic Orm for sqlite
upload_time2025-07-27 19:53:44
maintainerNone
docs_urlNone
authorDanilo Souza
requires_pythonNone
licenseMIT License
keywords sqlite orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# SimpleORM

SimpleORM is a lightweight and easy-to-use Object-Relational Mapping (ORM) utility for Python built on top of SQLite. It provides basic CRUD (Create, Read, Update, Delete) operations by mapping Python classes directly to SQLite tables, simplifying database interactions without requiring complex setup.

## Features

- Automatically creates SQLite tables based on Python class annotations.
- Insert Python objects into the database.
- Retrieve all or single records as Python objects.
- Delete records by object instance or ID.
- Supports basic Python types: `int`, `str`, `float`.

## Installation

No external dependencies are required besides Python's built-in `sqlite3` module. Just include the `SimpleORM` class in your project.

## Usage

1. Define your data model as a Python class with type annotations.

```python
class User:
    id: int
    name: str
    age: int
```
#### or 
```python
@dataclass
class User:
    id: int = field(init=False)
    name: str
    age: int
```
2. Create a `SimpleORM` instance with the SQLite database filename:

```python
from simple_orm import SimpleORM

orm = SimpleORM("mydatabase.db")
```

3. Create the corresponding table for your model:

```python
orm.create_table(User)
```

4. Insert objects:

```python
user = User()
user.name = "Alice"
user.age = 25
orm.insert(user)
print(user.id)  # Auto-generated ID
```
#### if usage dataclasses
```python
user = User(name='Alice', age=25)
# ID is auto-generated
```

5. Query all records:

```python
users = orm.get_all(User)
for u in users:
    print(u.id, u.name, u.age)
```

6. Query a single record by ID:

```python
user = orm.get_one(User, 1)
if user:
    print(user.name, user.age)
```
#### if you used dataclasses, make only
```python
if user:
    print(user)
```
because dataclasses add __repr__ 
7. Delete records:

```python
orm.delete(user)            # Delete by object
orm.delete_by_id(User, 2)  # Delete by ID
orm.delete_all(User)       # Delete all records for the class
```

## Limitations

- Supports only simple types (`int`, `str`, `float`).
- Does not support complex queries, relationships, or migrations.
- Assumes classes have an `id` attribute for primary keys.

## License

This project is released under the MIT License.

## how to contribute?

[create a PR on github](https://github.com/danilotec/pacotes)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "simple-orm-sqlite",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "sqlite orm",
    "author": "Danilo Souza",
    "author_email": "danilocrautomacao@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/45/5e/9a7702aee4dad12b5fd0bb0bd70426e9bb7278fdebf785c9ff59a8205e74/simple_orm_sqlite-0.0.3.tar.gz",
    "platform": null,
    "description": "\n# SimpleORM\n\nSimpleORM is a lightweight and easy-to-use Object-Relational Mapping (ORM) utility for Python built on top of SQLite. It provides basic CRUD (Create, Read, Update, Delete) operations by mapping Python classes directly to SQLite tables, simplifying database interactions without requiring complex setup.\n\n## Features\n\n- Automatically creates SQLite tables based on Python class annotations.\n- Insert Python objects into the database.\n- Retrieve all or single records as Python objects.\n- Delete records by object instance or ID.\n- Supports basic Python types: `int`, `str`, `float`.\n\n## Installation\n\nNo external dependencies are required besides Python's built-in `sqlite3` module. Just include the `SimpleORM` class in your project.\n\n## Usage\n\n1. Define your data model as a Python class with type annotations.\n\n```python\nclass User:\n    id: int\n    name: str\n    age: int\n```\n#### or \n```python\n@dataclass\nclass User:\n    id: int = field(init=False)\n    name: str\n    age: int\n```\n2. Create a `SimpleORM` instance with the SQLite database filename:\n\n```python\nfrom simple_orm import SimpleORM\n\norm = SimpleORM(\"mydatabase.db\")\n```\n\n3. Create the corresponding table for your model:\n\n```python\norm.create_table(User)\n```\n\n4. Insert objects:\n\n```python\nuser = User()\nuser.name = \"Alice\"\nuser.age = 25\norm.insert(user)\nprint(user.id)  # Auto-generated ID\n```\n#### if usage dataclasses\n```python\nuser = User(name='Alice', age=25)\n# ID is auto-generated\n```\n\n5. Query all records:\n\n```python\nusers = orm.get_all(User)\nfor u in users:\n    print(u.id, u.name, u.age)\n```\n\n6. Query a single record by ID:\n\n```python\nuser = orm.get_one(User, 1)\nif user:\n    print(user.name, user.age)\n```\n#### if you used dataclasses, make only\n```python\nif user:\n    print(user)\n```\nbecause dataclasses add __repr__ \n7. Delete records:\n\n```python\norm.delete(user)            # Delete by object\norm.delete_by_id(User, 2)  # Delete by ID\norm.delete_all(User)       # Delete all records for the class\n```\n\n## Limitations\n\n- Supports only simple types (`int`, `str`, `float`).\n- Does not support complex queries, relationships, or migrations.\n- Assumes classes have an `id` attribute for primary keys.\n\n## License\n\nThis project is released under the MIT License.\n\n## how to contribute?\n\n[create a PR on github](https://github.com/danilotec/pacotes)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Basic Orm for sqlite",
    "version": "0.0.3",
    "project_urls": null,
    "split_keywords": [
        "sqlite",
        "orm"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b5dc4c46a33a9622127c91e367defae382eff164af576023578b3a5b4e522c62",
                "md5": "6b283a915903401043abb44511e3346c",
                "sha256": "5200c8a9f904a23b92b73308d4ec2cfe5f96565c5648538af9bf53f419e31ddb"
            },
            "downloads": -1,
            "filename": "simple_orm_sqlite-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b283a915903401043abb44511e3346c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4345,
            "upload_time": "2025-07-27T19:53:43",
            "upload_time_iso_8601": "2025-07-27T19:53:43.285933Z",
            "url": "https://files.pythonhosted.org/packages/b5/dc/4c46a33a9622127c91e367defae382eff164af576023578b3a5b4e522c62/simple_orm_sqlite-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "455e9a7702aee4dad12b5fd0bb0bd70426e9bb7278fdebf785c9ff59a8205e74",
                "md5": "1b6fc583e99fcae322f02a74fb5edc60",
                "sha256": "df454944e7a8cc8df5f6c6e919dcf0bf1152c7ff9a84076f38aadfc0ee1334a1"
            },
            "downloads": -1,
            "filename": "simple_orm_sqlite-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1b6fc583e99fcae322f02a74fb5edc60",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3819,
            "upload_time": "2025-07-27T19:53:44",
            "upload_time_iso_8601": "2025-07-27T19:53:44.526741Z",
            "url": "https://files.pythonhosted.org/packages/45/5e/9a7702aee4dad12b5fd0bb0bd70426e9bb7278fdebf785c9ff59a8205e74/simple_orm_sqlite-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-27 19:53:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "simple-orm-sqlite"
}
        
Elapsed time: 1.43977s