Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aminalaee/sqlalchemy-model-builder
SQLAlchemy Random Model Builder for testing
https://github.com/aminalaee/sqlalchemy-model-builder
database orm python sqlalchemy sqlalchemy-model testing testing-tools
Last synced: 3 months ago
JSON representation
SQLAlchemy Random Model Builder for testing
- Host: GitHub
- URL: https://github.com/aminalaee/sqlalchemy-model-builder
- Owner: aminalaee
- License: mit
- Created: 2021-06-02T05:56:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-29T11:28:15.000Z (over 1 year ago)
- Last Synced: 2024-10-06T09:09:52.865Z (3 months ago)
- Topics: database, orm, python, sqlalchemy, sqlalchemy-model, testing, testing-tools
- Language: Python
- Homepage:
- Size: 46.9 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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_baseBase = 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 ModelBuilderrandom_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