sqlalchemy-model-builder


Namesqlalchemy-model-builder JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
SummarySQLAlchemy Model Builder
upload_time2023-06-29 11:28:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords sqlalchemy testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SQLAlchemy Model Builder
![test](https://github.com/aminalaee/sqlalchemy-model-builder/actions/workflows/test.yml/badge.svg) ![publish](https://github.com/aminalaee/sqlalchemy-model-builder/actions/workflows/publish.yml/badge.svg) [![codecov](https://codecov.io/gh/aminalaee/sqlalchemy-model-builder/branch/main/graph/badge.svg?token=QOLK6R9M52)](https://codecov.io/gh/aminalaee/sqlalchemy-model-builder) 
[![pypi](https://img.shields.io/pypi/v/sqlalchemy-model-builder?color=%2334D058&label=pypi)](https://pypi.org/project/sqlalchemy-model-builder/)

## Features
- Build SQLAlchemy model instance with random data
- Save SQLAlchemy model instance with random data
- Build relationships
- Build minimal (with required fields) only

---

## Installation

```shell
$ pip install sqlalchemy-model-builder
```

---

## How to use
Deinfe the SQLAlchemy models:

```python
from sqlalchemy import Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


class Address(Base):
    __tablename__ = "addresses"

    id = Column(Integer, primary_key=True)
    user_id = Column(Integer, ForeignKey("users.id"))
    user = relationship("User", back_populates="addresses")


class User(Base):
    __tablename__ = "users"

    addresses = relationship("Address", back_populates="user")
    bio = Column(Text)
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)

```

Save random model instance:

```python
from sqlalchemy_model_builder import ModelBuilder

random_user = ModelBuilder(User).save(db)
```

Build random model without saving:

```python
random_user = ModelBuilder(User).build()
```

Build minimal model instance:

```python
minimal_random_user = ModelBuilder(User, minimal=True).build()
```

Build or save with specific values:

```python
random_address = ModelBuilder(Address).build(user_id=1)
```

---

## Supported Data Types
- BigInteger
- Boolean
- Date
- DateTime
- Enum
- Float
- Integer
- Interval
- LargeBinary
- MatchType (Todo)
- Numeric
- PickleType (Todo)
- SchemaType (Todo)
- SmallInteger
- String
- Text
- Time
- Unicode
- UnicodeText

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sqlalchemy-model-builder",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "sqlalchemy,testing",
    "author": null,
    "author_email": "Amin Alaee <me@aminalaee.dev>",
    "download_url": "https://files.pythonhosted.org/packages/31/34/cbd275403ce60394e835eac0490b252f6c0e8b33bd35480c78e19c3a9815/sqlalchemy_model_builder-0.3.0.tar.gz",
    "platform": null,
    "description": "# SQLAlchemy Model Builder\n![test](https://github.com/aminalaee/sqlalchemy-model-builder/actions/workflows/test.yml/badge.svg) ![publish](https://github.com/aminalaee/sqlalchemy-model-builder/actions/workflows/publish.yml/badge.svg) [![codecov](https://codecov.io/gh/aminalaee/sqlalchemy-model-builder/branch/main/graph/badge.svg?token=QOLK6R9M52)](https://codecov.io/gh/aminalaee/sqlalchemy-model-builder) \n[![pypi](https://img.shields.io/pypi/v/sqlalchemy-model-builder?color=%2334D058&label=pypi)](https://pypi.org/project/sqlalchemy-model-builder/)\n\n## Features\n- Build SQLAlchemy model instance with random data\n- Save SQLAlchemy model instance with random data\n- Build relationships\n- Build minimal (with required fields) only\n\n---\n\n## Installation\n\n```shell\n$ pip install sqlalchemy-model-builder\n```\n\n---\n\n## How to use\nDeinfe the SQLAlchemy models:\n\n```python\nfrom sqlalchemy import Integer, String, Text\nfrom sqlalchemy.ext.declarative import declarative_base\n\nBase = declarative_base()\n\n\nclass Address(Base):\n    __tablename__ = \"addresses\"\n\n    id = Column(Integer, primary_key=True)\n    user_id = Column(Integer, ForeignKey(\"users.id\"))\n    user = relationship(\"User\", back_populates=\"addresses\")\n\n\nclass User(Base):\n    __tablename__ = \"users\"\n\n    addresses = relationship(\"Address\", back_populates=\"user\")\n    bio = Column(Text)\n    id = Column(Integer, primary_key=True)\n    name = Column(String, nullable=False)\n\n```\n\nSave random model instance:\n\n```python\nfrom sqlalchemy_model_builder import ModelBuilder\n\nrandom_user = ModelBuilder(User).save(db)\n```\n\nBuild random model without saving:\n\n```python\nrandom_user = ModelBuilder(User).build()\n```\n\nBuild minimal model instance:\n\n```python\nminimal_random_user = ModelBuilder(User, minimal=True).build()\n```\n\nBuild or save with specific values:\n\n```python\nrandom_address = ModelBuilder(Address).build(user_id=1)\n```\n\n---\n\n## Supported Data Types\n- BigInteger\n- Boolean\n- Date\n- DateTime\n- Enum\n- Float\n- Integer\n- Interval\n- LargeBinary\n- MatchType (Todo)\n- Numeric\n- PickleType (Todo)\n- SchemaType (Todo)\n- SmallInteger\n- String\n- Text\n- Time\n- Unicode\n- UnicodeText\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "SQLAlchemy Model Builder",
    "version": "0.3.0",
    "project_urls": {
        "Documentation": "https://github.com/aminalaee/sqlalchemy-model-builder",
        "Issues": "https://github.com/aminalaee/sqlalchemy-model-builder/issues",
        "Source": "https://github.com/aminalaee/sqlalchemy-model-builder"
    },
    "split_keywords": [
        "sqlalchemy",
        "testing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "82e5bb2f0bcff60645f67f75f24a1455ed4e24c588e42288f47f3119df09cf14",
                "md5": "0d7fa50155bd6874e9d379c538272002",
                "sha256": "b578086b97211340e18686a806cff71ab04f99c00d17db2830b248557f3170f2"
            },
            "downloads": -1,
            "filename": "sqlalchemy_model_builder-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d7fa50155bd6874e9d379c538272002",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6204,
            "upload_time": "2023-06-29T11:28:41",
            "upload_time_iso_8601": "2023-06-29T11:28:41.429593Z",
            "url": "https://files.pythonhosted.org/packages/82/e5/bb2f0bcff60645f67f75f24a1455ed4e24c588e42288f47f3119df09cf14/sqlalchemy_model_builder-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3134cbd275403ce60394e835eac0490b252f6c0e8b33bd35480c78e19c3a9815",
                "md5": "d7d225a9ecbb371f3f4d632f8bcee480",
                "sha256": "4230c18cb1c723197b363cd8af1f127a4d4e971021288653f1fd726718e9f2da"
            },
            "downloads": -1,
            "filename": "sqlalchemy_model_builder-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d7d225a9ecbb371f3f4d632f8bcee480",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7113,
            "upload_time": "2023-06-29T11:28:40",
            "upload_time_iso_8601": "2023-06-29T11:28:40.229893Z",
            "url": "https://files.pythonhosted.org/packages/31/34/cbd275403ce60394e835eac0490b252f6c0e8b33bd35480c78e19c3a9815/sqlalchemy_model_builder-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-29 11:28:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aminalaee",
    "github_project": "sqlalchemy-model-builder",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sqlalchemy-model-builder"
}
        
Elapsed time: 0.12882s